Skip to content

Instantly share code, notes, and snippets.

@steida
Created September 28, 2019 02:58
Show Gist options
  • Save steida/cba83a2ccf4495597ddf0c6eab1580b2 to your computer and use it in GitHub Desktop.
Save steida/cba83a2ccf4495597ddf0c6eab1580b2 to your computer and use it in GitHub Desktop.
// https://github.com/facebook/fbjs/blob/master/packages/fbjs/src/core/resolveImmediate.js
const resolvedPromise = Promise.resolve();
function throwNext(error: any) {
setTimeout(() => {
throw error;
}, 0);
}
/**
* An alternative to setImmediate based on Promise.
*/
export function resolveImmediate(callback: () => void) {
resolvedPromise.then(callback).catch(throwNext);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment