Skip to content

AbortSignal "signal abort" ordering #493

Closed
@jakearchibald

Description

@jakearchibald

https://dom.spec.whatwg.org/#abortsignal-signal-abort

Currently the order is:

  1. If signal’s aborted flag is set, then return.
  2. Set signal’s aborted flag.
  3. For each algorithm in signal’s abort algorithms: run algorithm.
  4. Empty signal’s abort algorithms.
  5. Fire an event named abort at signal.

If you want to create a new signal that copies another signal, you do something like this:

  1. Let originalSignal be a signal we got from somewhere.
  2. Let signal be a new AbortSignal.
  3. Add the following steps to originalSignal:
    1. Signal abort on signal.
  4. Return signal.

A side effect of this, is the "abort" event will despatch on signal before originalSignal.

const controller = new AbortController();
const signal = controller.signal;
const request = new Request('.', {signal});
const requestClone = request.clone(); // this copies the signal as above.

request.signal.addEventListener('abort', () => console.log('original'));
requestClone.signal.addEventListener('abort', () => console.log('clone'));

controller.abort();

In the code above, "clone" is logged before "original". Is this a problem?

cc @domenic @annevk @wycats @mikewest @bterlson @jyasskin

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions