lib: make AbortSignal cloneable/transferable
Refs: https://github.com/whatwg/dom/issues/948
Allows for using AbortSignal
across worker threads and contexts.
const ac = new AbortController();
const mc = new MessageChannel();
mc.port1.onmessage = ({ data }) => {
data.addEventListener('abort', () => {
console.log('aborted!');
});
};
mc.port2.postMessage(ac.signal, [ac.signal]);
Having to include the AbortSignal
in the transfer list here is a side effect of our current implementation. We use js_transferable
under the covers and use a pair of MessagePort
s to communicate between the two AbortSignal
s. Using [kClone]()
, there's no way for us to specify that the MessagePort
should be included in the transfer list as the [kTransferList]
method is not called when using [kClone]()
. So, we end up having to use [kTransfer]()
which requires that the AbortSignal
be included in the transfer list. (/cc @addaleax)
/cc @benjamingr
Signed-off-by: James M Snell jasnell@gmail.com