Closed
Description
From https://twitter.com/Dru89/status/976472959345815552
I've seen examples before where flushPromises
is written basically the way that you say:
const scheduler = typeof setImmedate === 'function' ? setImmediate : setTimeout;
export function flushPromises() {
return new Promise(res => scheduler(res));
}
What I don't really understand is why this actually works. I'm assuming it has something to do with scheduling and how JavaScript actually handles asynchronous published behavior.
And relatedly:
Is this a "hack" that only works because of an implementation detail in Node/V8? (Would this break in a browser or in something like Chakra?) If it's not something in the spec, is it something that's likely to change?