3 ms·
The biggest problem I had with forced promise asynchronicity was with browser promise polyfills, which use setTimeout to force success and error handlers to be
by bluepnume 9y ago
The biggest problem I had with forced promise asynchronicity was with browser promise polyfills, which use setTimeout to force success and error handlers to be called asynchronously.
This is fine, unless you're:
1. Modifying the DOM and hoping to avoid jankiness
2. Trying to work with popup windows, in a browser which deprioritizes setTimeout in all but the focused window.
I ended up implementing https://github.com/krakenjs/zalgo-promise https://github.com/krakenjs/zalgo-promise to get around this. It intentionally "releases Zalgo" by allowing promises to be resolved/then'd synchronously, but my belief is this doesn't have to cause bugs if it's used consistently.
- Arnavion 9y agoYou're using poor polyfills if they use setTimeout. Good polyfills [1] use MutationObserver which uses the (a?) microtask queue. Invoking a Promise's then() callback synchronously is a violation of the spec. IIRC there are some tests to prevent that in the test suite. [1]: https://github.com/petkaantonov/bluebird/blob/2c9f7a44/src/schedule.js#L31 https://github.com/petkaantonov/bluebird/blob/2c9f7a44/src/s...