diff options
Diffstat (limited to 'deps/npm/node_modules/npm-profile/node_modules/make-fetch-happen/node_modules/socks-proxy-agent/node_modules/agent-base/node_modules/es6-promisify/node_modules/es6-promise/lib/es6-promise/promise.js')
1 files changed, 29 insertions, 72 deletions
diff --git a/deps/npm/node_modules/npm-profile/node_modules/make-fetch-happen/node_modules/socks-proxy-agent/node_modules/agent-base/node_modules/es6-promisify/node_modules/es6-promise/lib/es6-promise/promise.js b/deps/npm/node_modules/npm-profile/node_modules/make-fetch-happen/node_modules/socks-proxy-agent/node_modules/agent-base/node_modules/es6-promisify/node_modules/es6-promise/lib/es6-promise/promise.js index 8d8f829c5e..20558cbeea 100644 --- a/deps/npm/node_modules/npm-profile/node_modules/make-fetch-happen/node_modules/socks-proxy-agent/node_modules/agent-base/node_modules/es6-promisify/node_modules/es6-promise/lib/es6-promise/promise.js +++ b/deps/npm/node_modules/npm-profile/node_modules/make-fetch-happen/node_modules/socks-proxy-agent/node_modules/agent-base/node_modules/es6-promisify/node_modules/es6-promise/lib/es6-promise/promise.js @@ -1,12 +1,14 @@ import { isFunction } from './utils'; + import { noop, nextId, PROMISE_ID, initializePromise } from './-internal'; + import { asap, setAsap, @@ -19,6 +21,7 @@ import Resolve from './promise/resolve'; import Reject from './promise/reject'; import then from './then'; + function needsResolver() { throw new TypeError('You must pass a resolver function as the first argument to the promise constructor'); } @@ -126,24 +129,33 @@ function needsNew() { ``` @class Promise - @param {Function} resolver + @param {function} resolver Useful for tooling. @constructor */ +export default function Promise(resolver) { + this[PROMISE_ID] = nextId(); + this._result = this._state = undefined; + this._subscribers = []; + + if (noop !== resolver) { + typeof resolver !== 'function' && needsResolver(); + this instanceof Promise ? initializePromise(this, resolver) : needsNew(); + } +} -class Promise { - constructor(resolver) { - this[PROMISE_ID] = nextId(); - this._result = this._state = undefined; - this._subscribers = []; +Promise.all = all; +Promise.race = race; +Promise.resolve = Resolve; +Promise.reject = Reject; +Promise._setScheduler = setScheduler; +Promise._setAsap = setAsap; +Promise._asap = asap; - if (noop !== resolver) { - typeof resolver !== 'function' && needsResolver(); - this instanceof Promise ? initializePromise(this, resolver) : needsNew(); - } - } +Promise.prototype = { + constructor: Promise, - /** +/** The primary way of interacting with a promise is through its `then` method, which registers callbacks to receive either a promise's eventual value or the reason why the promise cannot be fulfilled. @@ -335,9 +347,10 @@ class Promise { @param {Function} onRejected Useful for tooling. @return {Promise} - */ +*/ + then: then, - /** +/** `catch` is simply sugar for `then(undefined, onRejection)` which makes it the same as the catch block of a try/catch statement. @@ -363,64 +376,8 @@ class Promise { @param {Function} onRejection Useful for tooling. @return {Promise} - */ +*/ catch(onRejection) { return this.then(null, onRejection); } - -/** - `finally` will be invoked regardless of the promise's fate just as native - try/catch/finally behaves - - Synchronous example: - - ```js - findAuthor() { - if (Math.random() > 0.5) { - throw new Error(); - } - return new Author(); - } - - try { - return findAuthor(); // succeed or fail - } catch(error) { - return findOtherAuther(); - } finally { - // always runs - // doesn't affect the return value - } - ``` - - Asynchronous example: - - ```js - findAuthor().catch(function(reason){ - return findOtherAuther(); - }).finally(function(){ - // author was either found, or not - }); - ``` - - @method finally - @param {Function} callback - @return {Promise} -*/ - finally(callback) { - let promise = this; - let constructor = promise.constructor; - - return promise.then(value => constructor.resolve(callback()).then(() => value), - reason => constructor.resolve(callback()).then(() => { throw reason; })); - } -} - -Promise.prototype.then = then; -export default Promise; -Promise.all = all; -Promise.race = race; -Promise.resolve = Resolve; -Promise.reject = Reject; -Promise._setScheduler = setScheduler; -Promise._setAsap = setAsap; -Promise._asap = asap; +}; |