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-promiseUsage
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 resolvedDeferred
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 passed value.
deferred.reject(value);.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;