Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: then/promise
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 90757a38c86975f36893012581b72315b352d482
Choose a base ref
...
head repository: then/promise
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: cebfa6049cc08843f428c6fc92dde918f8687e6d
Choose a head ref
  • 10 commits
  • 7 files changed
  • 4 contributors

Commits on Dec 23, 2015

  1. Release 7.1.1

    ForbesLindesay committed Dec 23, 2015
    Copy the full SHA
    c91e182 View commit details
  2. Update badges

    ForbesLindesay committed Dec 23, 2015

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    1c5fcf2 View commit details

Commits on Jun 8, 2016

  1. semicolon fix (#127)

    denisx authored and ForbesLindesay committed Jun 8, 2016

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    453f845 View commit details

Commits on Jul 27, 2016

  1. Copy the full SHA
    06f2400 View commit details

Commits on Sep 9, 2016

  1. Fix error message typo

    edef1c committed Sep 9, 2016
    Copy the full SHA
    7f33b7b View commit details

Commits on Jun 15, 2017

  1. Add typescript support

    ForbesLindesay committed Jun 15, 2017
    Copy the full SHA
    9809ef4 View commit details
  2. Release 7.2.0

    ForbesLindesay committed Jun 15, 2017
    Copy the full SHA
    e9e8574 View commit details

Commits on Jun 16, 2017

  1. Add flow support

    ForbesLindesay committed Jun 16, 2017
    Copy the full SHA
    6cd53d3 View commit details
  2. Release 7.3.0

    ForbesLindesay committed Jun 16, 2017
    Copy the full SHA
    819ecbc View commit details

Commits on Jun 19, 2017

  1. Copy the full SHA
    cebfa60 View commit details
Showing with 269 additions and 12 deletions.
  1. +2 −1 .gitignore
  2. +2 −2 Readme.md
  3. +1 −1 component.json
  4. +256 −0 index.d.ts
  5. +2 −2 package.json
  6. +3 −3 src/core.js
  7. +3 −3 src/node-extensions.js
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -4,4 +4,5 @@ node_modules
/lib
/domains
/setimmediate
coverage
coverage
package-lock.json
4 changes: 2 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -14,8 +14,8 @@ For detailed tutorials on its use, see www.promisejs.org

[travis-image]: https://img.shields.io/travis/then/promise.svg?style=flat
[travis-url]: https://travis-ci.org/then/promise
[dep-image]: https://img.shields.io/gemnasium/then/promise.svg?style=flat
[dep-url]: https://gemnasium.com/then/promise
[dep-image]: https://img.shields.io/david/then/promise.svg?style=flat
[dep-url]: https://david-dm.org/then/promise
[npm-image]: https://img.shields.io/npm/v/promise.svg?style=flat
[npm-url]: https://npmjs.org/package/promise
[downloads-image]: https://img.shields.io/npm/dm/promise.svg?style=flat
2 changes: 1 addition & 1 deletion component.json
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
"name": "promise",
"repo": "then/promise",
"description": "Bare bones Promises/A+ implementation",
"version": "7.0.3",
"version": "7.3.0",
"keywords": [],
"dependencies": {
"johntron/asap": "*"
256 changes: 256 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
interface Thenable<T> {
/**
* Attaches callbacks for the resolution and/or rejection of the ThenPromise.
* @param onfulfilled The callback to execute when the ThenPromise is resolved.
* @param onrejected The callback to execute when the ThenPromise is rejected.
* @returns A ThenPromise for the completion of which ever callback is executed.
*/
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | Thenable<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | Thenable<TResult2>) | undefined | null): Thenable<TResult1 | TResult2>;
}

/**
* Represents the completion of an asynchronous operation
*/
interface ThenPromise<T> {
/**
* Attaches callbacks for the resolution and/or rejection of the ThenPromise.
* @param onfulfilled The callback to execute when the ThenPromise is resolved.
* @param onrejected The callback to execute when the ThenPromise is rejected.
* @returns A ThenPromise for the completion of which ever callback is executed.
*/
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | Thenable<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | Thenable<TResult2>) | undefined | null): ThenPromise<TResult1 | TResult2>;

/**
* Attaches a callback for only the rejection of the ThenPromise.
* @param onrejected The callback to execute when the ThenPromise is rejected.
* @returns A ThenPromise for the completion of the callback.
*/
catch<TResult = never>(onrejected?: ((reason: any) => TResult | Thenable<TResult>) | undefined | null): ThenPromise<T | TResult>;

// Extensions specific to then/promise

/**
* Attaches callbacks for the resolution and/or rejection of the ThenPromise, without returning a new promise.
* @param onfulfilled The callback to execute when the ThenPromise is resolved.
* @param onrejected The callback to execute when the ThenPromise is rejected.
*/
done(onfulfilled?: ((value: T) => any) | undefined | null, onrejected?: ((reason: any) => any) | undefined | null): void;


/**
* Calls a node.js style callback. If none is provided, the promise is returned.
*/
nodeify(callback: void | null): ThenPromise<T>;
nodeify(callback: (err: Error, value: T) => void): void;
}

interface ThenPromiseConstructor {
/**
* A reference to the prototype.
*/
readonly prototype: ThenPromise<any>;

/**
* Creates a new ThenPromise.
* @param executor A callback used to initialize the promise. This callback is passed two arguments:
* a resolve callback used resolve the promise with a value or the result of another promise,
* and a reject callback used to reject the promise with a provided reason or error.
*/
new <T>(executor: (resolve: (value?: T | Thenable<T>) => void, reject: (reason?: any) => void) => any): ThenPromise<T>;

/**
* Creates a ThenPromise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any ThenPromise is rejected.
* @param values An array of Promises.
* @returns A new ThenPromise.
*/
all<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(values: [T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>, T4 | Thenable <T4>, T5 | Thenable<T5>, T6 | Thenable<T6>, T7 | Thenable<T7>, T8 | Thenable<T8>, T9 | Thenable<T9>, T10 | Thenable<T10>]): ThenPromise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>;

/**
* Creates a ThenPromise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any ThenPromise is rejected.
* @param values An array of Promises.
* @returns A new ThenPromise.
*/
all<T1, T2, T3, T4, T5, T6, T7, T8, T9>(values: [T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>, T4 | Thenable <T4>, T5 | Thenable<T5>, T6 | Thenable<T6>, T7 | Thenable<T7>, T8 | Thenable<T8>, T9 | Thenable<T9>]): ThenPromise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>;

/**
* Creates a ThenPromise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any ThenPromise is rejected.
* @param values An array of Promises.
* @returns A new ThenPromise.
*/
all<T1, T2, T3, T4, T5, T6, T7, T8>(values: [T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>, T4 | Thenable <T4>, T5 | Thenable<T5>, T6 | Thenable<T6>, T7 | Thenable<T7>, T8 | Thenable<T8>]): ThenPromise<[T1, T2, T3, T4, T5, T6, T7, T8]>;

/**
* Creates a ThenPromise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any ThenPromise is rejected.
* @param values An array of Promises.
* @returns A new ThenPromise.
*/
all<T1, T2, T3, T4, T5, T6, T7>(values: [T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>, T4 | Thenable <T4>, T5 | Thenable<T5>, T6 | Thenable<T6>, T7 | Thenable<T7>]): ThenPromise<[T1, T2, T3, T4, T5, T6, T7]>;

/**
* Creates a ThenPromise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any ThenPromise is rejected.
* @param values An array of Promises.
* @returns A new ThenPromise.
*/
all<T1, T2, T3, T4, T5, T6>(values: [T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>, T4 | Thenable <T4>, T5 | Thenable<T5>, T6 | Thenable<T6>]): ThenPromise<[T1, T2, T3, T4, T5, T6]>;

/**
* Creates a ThenPromise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any ThenPromise is rejected.
* @param values An array of Promises.
* @returns A new ThenPromise.
*/
all<T1, T2, T3, T4, T5>(values: [T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>, T4 | Thenable <T4>, T5 | Thenable<T5>]): ThenPromise<[T1, T2, T3, T4, T5]>;

/**
* Creates a ThenPromise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any ThenPromise is rejected.
* @param values An array of Promises.
* @returns A new ThenPromise.
*/
all<T1, T2, T3, T4>(values: [T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>, T4 | Thenable <T4>]): ThenPromise<[T1, T2, T3, T4]>;

/**
* Creates a ThenPromise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any ThenPromise is rejected.
* @param values An array of Promises.
* @returns A new ThenPromise.
*/
all<T1, T2, T3>(values: [T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>]): ThenPromise<[T1, T2, T3]>;

/**
* Creates a ThenPromise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any ThenPromise is rejected.
* @param values An array of Promises.
* @returns A new ThenPromise.
*/
all<T1, T2>(values: [T1 | Thenable<T1>, T2 | Thenable<T2>]): ThenPromise<[T1, T2]>;

/**
* Creates a ThenPromise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any ThenPromise is rejected.
* @param values An array of Promises.
* @returns A new ThenPromise.
*/
all<T>(values: (T | Thenable<T>)[]): ThenPromise<T[]>;

/**
* Creates a ThenPromise that is resolved or rejected when any of the provided Promises are resolved
* or rejected.
* @param values An array of Promises.
* @returns A new ThenPromise.
*/
race<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(values: [T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>, T4 | Thenable<T4>, T5 | Thenable<T5>, T6 | Thenable<T6>, T7 | Thenable<T7>, T8 | Thenable<T8>, T9 | Thenable<T9>, T10 | Thenable<T10>]): ThenPromise<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9 | T10>;

/**
* Creates a ThenPromise that is resolved or rejected when any of the provided Promises are resolved
* or rejected.
* @param values An array of Promises.
* @returns A new ThenPromise.
*/
race<T1, T2, T3, T4, T5, T6, T7, T8, T9>(values: [T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>, T4 | Thenable<T4>, T5 | Thenable<T5>, T6 | Thenable<T6>, T7 | Thenable<T7>, T8 | Thenable<T8>, T9 | Thenable<T9>]): ThenPromise<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9>;

/**
* Creates a ThenPromise that is resolved or rejected when any of the provided Promises are resolved
* or rejected.
* @param values An array of Promises.
* @returns A new ThenPromise.
*/
race<T1, T2, T3, T4, T5, T6, T7, T8>(values: [T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>, T4 | Thenable<T4>, T5 | Thenable<T5>, T6 | Thenable<T6>, T7 | Thenable<T7>, T8 | Thenable<T8>]): ThenPromise<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8>;

/**
* Creates a ThenPromise that is resolved or rejected when any of the provided Promises are resolved
* or rejected.
* @param values An array of Promises.
* @returns A new ThenPromise.
*/
race<T1, T2, T3, T4, T5, T6, T7>(values: [T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>, T4 | Thenable<T4>, T5 | Thenable<T5>, T6 | Thenable<T6>, T7 | Thenable<T7>]): ThenPromise<T1 | T2 | T3 | T4 | T5 | T6 | T7>;

/**
* Creates a ThenPromise that is resolved or rejected when any of the provided Promises are resolved
* or rejected.
* @param values An array of Promises.
* @returns A new ThenPromise.
*/
race<T1, T2, T3, T4, T5, T6>(values: [T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>, T4 | Thenable<T4>, T5 | Thenable<T5>, T6 | Thenable<T6>]): ThenPromise<T1 | T2 | T3 | T4 | T5 | T6>;

/**
* Creates a ThenPromise that is resolved or rejected when any of the provided Promises are resolved
* or rejected.
* @param values An array of Promises.
* @returns A new ThenPromise.
*/
race<T1, T2, T3, T4, T5>(values: [T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>, T4 | Thenable<T4>, T5 | Thenable<T5>]): ThenPromise<T1 | T2 | T3 | T4 | T5>;

/**
* Creates a ThenPromise that is resolved or rejected when any of the provided Promises are resolved
* or rejected.
* @param values An array of Promises.
* @returns A new ThenPromise.
*/
race<T1, T2, T3, T4>(values: [T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>, T4 | Thenable<T4>]): ThenPromise<T1 | T2 | T3 | T4>;

/**
* Creates a ThenPromise that is resolved or rejected when any of the provided Promises are resolved
* or rejected.
* @param values An array of Promises.
* @returns A new ThenPromise.
*/
race<T1, T2, T3>(values: [T1 | Thenable<T1>, T2 | Thenable<T2>, T3 | Thenable<T3>]): ThenPromise<T1 | T2 | T3>;

/**
* Creates a ThenPromise that is resolved or rejected when any of the provided Promises are resolved
* or rejected.
* @param values An array of Promises.
* @returns A new ThenPromise.
*/
race<T1, T2>(values: [T1 | Thenable<T1>, T2 | Thenable<T2>]): ThenPromise<T1 | T2>;

/**
* Creates a ThenPromise that is resolved or rejected when any of the provided Promises are resolved
* or rejected.
* @param values An array of Promises.
* @returns A new ThenPromise.
*/
race<T>(values: (T | Thenable<T>)[]): ThenPromise<T>;

/**
* Creates a new rejected promise for the provided reason.
* @param reason The reason the promise was rejected.
* @returns A new rejected ThenPromise.
*/
reject(reason: any): ThenPromise<never>;

/**
* Creates a new rejected promise for the provided reason.
* @param reason The reason the promise was rejected.
* @returns A new rejected ThenPromise.
*/
reject<T>(reason: any): ThenPromise<T>;

/**
* Creates a new resolved promise for the provided value.
* @param value A promise.
* @returns A promise whose internal state matches the provided promise.
*/
resolve<T>(value: T | Thenable<T>): ThenPromise<T>;

/**
* Creates a new resolved promise .
* @returns A resolved promise.
*/
resolve(): ThenPromise<void>;

// Extensions specific to then/promise

denodeify: (fn: Function) => (...args: any[]) => ThenPromise<any>;
nodeify: (fn: Function) => Function;
}

declare var ThenPromise: ThenPromiseConstructor;

export = ThenPromise;
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "promise",
"version": "7.0.4",
"version": "7.3.0",
"description": "Bare bones Promises/A+ implementation",
"main": "index.js",
"scripts": {
@@ -32,4 +32,4 @@
"dependencies": {
"asap": "~2.0.3"
}
}
}
6 changes: 3 additions & 3 deletions src/core.js
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ function Promise(fn) {
throw new TypeError('Promises must be constructed via new');
}
if (typeof fn !== 'function') {
throw new TypeError('not a function');
throw new TypeError('Promise constructor\'s argument is not a function');
}
this._deferredState = 0;
this._state = 0;
@@ -84,7 +84,7 @@ function safeThen(self, onFulfilled, onRejected) {
res.then(resolve, reject);
handle(self, new Handler(onFulfilled, onRejected, res));
});
};
}
function handle(self, deferred) {
while (self._state === 3) {
self = self._value;
@@ -205,7 +205,7 @@ function doResolve(fn, promise) {
if (done) return;
done = true;
reject(promise, reason);
})
});
if (!done && res === IS_ERROR) {
done = true;
reject(promise, LAST_ERROR);
6 changes: 3 additions & 3 deletions src/node-extensions.js
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ Promise.denodeify = function (fn, argumentCount) {
} else {
return denodeifyWithoutCount(fn);
}
}
};

var callbackFn = (
'function (err, res) {' +
@@ -113,7 +113,7 @@ Promise.nodeify = function (fn) {
}
}
}
}
};

Promise.prototype.nodeify = function (callback, ctx) {
if (typeof callback != 'function') return this;
@@ -127,4 +127,4 @@ Promise.prototype.nodeify = function (callback, ctx) {
callback.call(ctx, err);
});
});
}
};