1.1.0 • Published 11 years ago

promise-now v1.1.0

Weekly downloads
29
License
-
Repository
github
Last release
11 years ago

Promise Now

Barebone Promise/A+ implementation. .then() being asynchronous is optional.

Installation

npm install promise-now

Example

var Promise = require('promise-now');
var promise = new Promise();

promise.then(addOne).then(addOne).then(function(num) {
	console.log(num); // 3
});
promise.fulfill(1);

function addOne(num) {
	return num + 1;
}

API

promise.then(fulfullCallack, rejectCallback);

See the Q tutorial, if you are not familiar with promises.

promise.fulfill(value);

Fullfil promise with value. This method only exists on the promises created by new Promise(), not on promises returned by .then().

Returns promise.

promise.reject(reason);

Reject promise with reason. This method only exists on the promises created by new Promise(), not on promises returned by .then().

Returns promise.

Optionally being asynchonous

If you can be sure that you will never write code like:

var promise = new Promise().fulfill();

promise.then(function() {
	console.log(2);
});
console.log(1);

In other words, you will not put synchronous code after asynchronous function calls, it doesn't make a difference if .then() is asynchronous or not.

By default, promise-now use synchronous .then(). If you need the asynchronous version, consider using another promise library, or patch promise-now youself (see test/promise.js on how it's done).

1.1.0

11 years ago

1.0.0

11 years ago

0.6.0

11 years ago

0.5.1

11 years ago

0.4.1

11 years ago

0.4.0

11 years ago

0.3.0

11 years ago

0.2.2

11 years ago

0.2.1

11 years ago

0.2.0

11 years ago

0.1.0

11 years ago