Re: [whatwg/fetch] Proposal: fetch with multiple AbortSignals (#905)

Nice! Yeah I just learned about it yesterday. It’s not supported by node.js yet but is supported by Jsdom so should be good for testing browser code.
Re. implementation, there is a memory leak if returning early, it’s important to abort the controller too.
________________________________
From: Jake Archibald ***@***.***>
Sent: 11 February 2023 12:55 AM
To: whatwg/fetch ***@***.***>
Cc: Alon Gamliel ***@***.***>; Comment ***@***.***>
Subject: Re: [whatwg/fetch] Proposal: fetch with multiple AbortSignals (#905)


fwiw, it can be simplified further:

function anySignal(signals: AbortSignal[]) {

  const controller = new AbortController();



  for (const signal of signals) {

    if (signal.aborted) return signal;



    signal.addEventListener("abort", () => controller.abort(signal.reason), {

      signal: controller.signal,

    });

  }



  return controller.signal;

}

…now that signals can be used to remove event listeners.

—
Reply to this email directly, view it on GitHub<https://github.com/whatwg/fetch/issues/905#issuecomment-1425708260>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AB7TOENBK3FI6QQ6EF5TGETWWYUERANCNFSM4HMG6GOA>.
You are receiving this because you commented.Message ID: ***@***.***>


-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/fetch/issues/905#issuecomment-1426273989

You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/fetch/issues/905/1426273989@github.com>

Received on Friday, 10 February 2023 20:00:45 UTC