JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 15
  • Score
    100M100P100Q45619F
  • License MIT

Just another promise library.

Package Exports

  • bauer-promise

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (bauer-promise) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

node-bauer-promise

This is just another promise library. It relies on Thisable and unlike the compliant implementations, it features the possibility of binding context to callbacks.

Installation

npm install bauer-promise

Usage

var P = require("bauer-promise");

P.defer(); // returns a deferred object
P.defer(object); // binds object to the created promise

P.when(value); // returns a promise resolved with value
P.when(a,b,c,d); // returns a promise resolved with an array [a,b,c,d]
P.when(promise,promise,promise) // wait until all promises are resolved

Deferred

Constructor

Creates a common deferred object.

var deferred = P.defer()
// same as
var deferred = new P.cls.Deferred()

Creates a deferred object with the passed object bound to the promise.

var deferred = P.defer(object)
// same as
var deferred = new P.cls.Deferred(object)

.bind

Binds the passed object to the deferreds promise.

deferred.bind(object);
// same as
deferred.promise.bind(object);

.resolve

Fulfills the promise with the passed value.

deferred.resolve(value);

.reject

Rejects the promise with the given reason.

deferred.reject(reason);

.promise

Holds the promise itself. This is what should be returned when writing an async procedure.

var deferred = P.defer();
fs.readFile("path/to/file",function(error,content) {
    if (error) {
        deferred.reject(error);
    } else {
        deferred.resolve(content);
    }
});
return deferred.promise;

Promise

Constructor

var promise = new P.cls.Promise()

.bind

Binds the passed object to the promise.

promise.bind(object);

.then

Attach a callback to be executed when the promise is fulfilled. The second callback is called if the promise is rejected or throws an error. If .bind was called before then this refers to the bound object inside both callbacks. It returns another promise to allow chaining.

promise.then(function(value) {
    // promise is fulfilled with value
},function(reason) {
    // promise is rejected with reason
});

.fail

Attach a callback to be executed when the promise is rejected or throws an error. If .bind was called before then this refers to the bound object inside the callback. It returns another promise to allow chaining.

promise.fail(function(reason) {});
// same as
promise.then(null,function(reason) {});

.done

Same thing as .then excepts that it returns nothing. Once done is called any unhandled exception is thrown in a future loop.

promise.done(function(value) {
    // promise is fulfilled with value
},function(reason) {
    // promise is rejected with reason
});

.fulfill

Fulfill the promise with the passed value.

promise.fulfill(value);
// same as
deferred.resolve(value);

.reject

Rejects the promise with the given reason.

promise.fulfill(value);
// same as
deferred.resolve(value);

License

MIT