Re: [whatwg/dom] Abort controller design (#438)

I wonder if we can do something to aid extensibility here, so a subclass could do something like:

A FetchSignal has an associated priority, which is a number. It is serializable.

Then, to update the priority of a fetch signal to newPriority:

1. If signal's priority equals newPriority, return.
1. Set signal's priority to newPriority.
1. Fire an event named 'prioritychange' at signal.
1. Broadcast to cloned listeners to run "update the priority of a signal" with newPriority.

Some rough scribblings around how this could work:

Then AbortSignal's serialize steps could be:

1. Let channel be a new MessageChannel object.
1. Append channel's port1 to value's outgoing ports.
1. For each serializable item:
  1. If the item is a flag and is set, set serialized.[[(the item's name)]] to true.
  1. Else if the item is a number, set serialized.[[(the item's name)]] to the number.
1. Set serialized.[[IncomingPort]] to ! StructuredSerializeWithTransfer(channel's port2, channel's port2).

To deserialize AbortSignal:

1. Set value's incoming port to ! StructuredDeserializeWithTransfer(serialized.[[IncomingPort]], the current Realm).
1. Remove serialized.[[IncomingPort]].
1. For each key, serializedValue in serialized:
  1. If serializedValue is a boolean, set the flag on value named key
  2. Else set the property (these aren't properties are they? What are they?) on value named key to serializedValue.
1. Append an event listener to value's incoming port listening for "message" events that runs these steps with the event e:
  1. Run the algorithm named e.data.algorithm, with arugments e.data.arguments.
1. Enable value's incoming port.

To broadcast to cloned listeners a given algorithm name and array of arguments:

1. Let data be a new object.
1. Set data.algorithm to the given algorithm name.
1. Set data.arguments to the array of arguments.
1. For each port of signal's outgoing ports:
  1. Post a message to the port with data


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/438#issuecomment-307070122

Received on Thursday, 8 June 2017 10:56:49 UTC