Skip to content

gobwas/broody-promises

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

broody-promises

Build Status

Broody implementation of Promises/A+.

Whats up?

Promises/A+ logo

Broody promises is a minimalistic lightweight (~1.5KB gzipped) implementation of Promises/A+, with ability to retrieve fulfilled value. Of course, it is possible to do that just when all chain of thens and catchs are resolved synchronous. In other way usage of Broodies did not make any sense to you, because it has no any preferences over already existing and great Promises/A+ libraries.

Getting started

Install with npm

npm install --save broody-promises

Overview

	
	var promise, chain;

	promise = new Promise(function(resolve, reject) {
		// resolve now synchronous
		resolve("my value");
	});

	chain = Promise.sync(function() {
		return promise
			.then(function(value) {
				// again synchronous
				return value + "!";
			});
	});

	chain.result(); // my value!

API

new Promise(resolver: Function(resolve: Function(value: any), reject: Function(reason: any)))
promise.then(onResolve: Function(value: any), onReject: Function(reason: any)) -> Promise
promise.catch(onReject: Function(reason: any)) -> Promise
promise.finally(anyWay: Function(error: any, value: any)) -> Promise
promise.result() -> any

Returns resolved value.

Throws an error in two cases:

  • target promise is in pending state.
  • target promise was rejected.
promise.isPending() -> Boolean
promise.isFulfilled() -> Boolean
promise.isRejected() -> Boolean

Promise.sync(fn: Function()) -> any

Enters in a new context with given functon, when any new Promise (created synchronously) will have synchronous resolution of onFulfilled and onRejected callbacks in .then chains. This brings ability to use .result() method.

Note, that with this feature, Broodies will not pass the 2.2.4 rule of the Promises/A+ spec.

Promise.all(promises: Array[Promise]) -> Promise
Promise.resolve(value: any) -> Promise

Returns new resolved Promise.

Promise.reject(error: any) -> Promise

Returns new rejected Promise.

About

Broody implementation of Promise A+.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published