layered-apis icon indicating copy to clipboard operation
layered-apis copied to clipboard

Avoiding magic when calling callbacks

Open jakearchibald opened this issue 7 years ago • 1 comments

If I have a spec like:

  1. Let obj be a new object.
  2. Invoke callback with obj.
  3. Do something with obj.

…microtasks will be handled after step two. But there's no way to do this in a JavaScript implementation of the spec, as the stack won't be empty.

Either we need to spec the above in a way that prevents a microtask checkpoint after step two (which would be weird if the API is ever promoted into the HTML spec or whatever), or we need to provide a way to process microtasks synchronously.

jakearchibald avatar Feb 13 '18 12:02 jakearchibald

Microtasks will not be handled after step 2 unless those steps are surrounded by "queue a task" or similar, which is more rare. In that case we'd probably need some new way of queuing a task that makes it clear we're running JS code, yeah. For example "queue task: 1. prepare to run script; 2-4. your steps. 5. clean up after running script".

domenic avatar Feb 13 '18 17:02 domenic