drufball / layered-apis

A new standards effort for collaborating on high-level features.
275 stars 12 forks source link

Avoiding magic when calling callbacks #4

Open jakearchibald opened 6 years ago

jakearchibald commented 6 years ago

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.

domenic commented 6 years ago

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".