4 ms·
I don't think they will be. Cancellation of a task after it has started in JS is fundamentally unsafe since you don't have destructors for cleaning up code mid
by slaymaker1907 5y ago
I don't think they will be. Cancellation of a task after it has started in JS is fundamentally unsafe since you don't have destructors for cleaning up code mid execution. The best thing you could do would be to have cancellation work as an exception whenever you call await that can be caught.
- dangerbird2 5y agoJavascript does have finalizers now[1], which is a much-needed feature for webassembly interop where you need to explicitly call destructors to clean up any wasm data the object owns. However, this wouldn't help with promises where you need cleanup code to be called deterministically, not whenever the GC gets around to cleaning up the object. As you mention, using cancellation tokens that raise an exception is a reasonable solution [1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- noduerme 5y agoI'm not sure I understand the distinction. Right now if you throw an exception inside an async function, that "cancels" it and the function's object references are eventually GC'd. You catch the exception outside the promise. I'd imagine external cancellations would work in a similar way. Why is it unsafe for something outside to tell the async function to just throw an exception now, halt and dump its object references? If you're planning on explicitly doing it you'd need to catch it anyway. The difference is being able to do it from outside once the async function is running.