Socket
Book a DemoInstallSign in
Socket

broody-promises

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

broody-promises

Broody implementation of Promises/A+

latest
Source
npmnpm
Version
0.5.1
Version published
Weekly downloads
6
50%
Maintainers
1
Weekly downloads
 
Created
Source

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 .value() 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.

Keywords

promises-aplus

FAQs

Package last updated on 11 Jun 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts