Skip to content

Instantly share code, notes, and snippets.

@FrankV01
Last active July 6, 2017 21:21
Show Gist options
  • Save FrankV01/f2b8d4bd4aab351f3e66404c74be29ff to your computer and use it in GitHub Desktop.
Save FrankV01/f2b8d4bd4aab351f3e66404c74be29ff to your computer and use it in GitHub Desktop.
//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);
}
// 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