Created
September 28, 2019 02:58
-
-
Save steida/cba83a2ccf4495597ddf0c6eab1580b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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