Last active
July 6, 2017 21:21
-
-
Save FrankV01/f2b8d4bd4aab351f3e66404c74be29ff to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//Sourced from https://github.com/TheOpenSourceU/pinkie/blob/tOSU/article/index.js#L170 | |
function Promise(resolver) { | |
if (typeof resolver !== 'function') { | |
throw new TypeError('Promise resolver ' + resolver + ' is not a function'); | |
} | |
if (this instanceof Promise === false) { | |
throw new TypeError('Failed to construct \'Promise\': Please use the \'new\' operator, this object constructor cannot be called as a function.'); | |
} | |
this._then = []; | |
invokeResolver(resolver, this); | |
} |
This file contains hidden or 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
// Sourced from https://github.com/TheOpenSourceU/pinkie/blob/tOSU/article/index.js#L34 | |
function invokeResolver(resolver, promise) { | |
function resolvePromise(value) { | |
resolve(promise, value); | |
} | |
function rejectPromise(reason) { | |
reject(promise, reason); | |
} | |
try { | |
resolver(resolvePromise, rejectPromise); | |
} catch (e) { | |
rejectPromise(e); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment