Oath constructor
Oath()
Create a new promise.
Options
- parent - used internally for chaining
- context - object to set as
this
in callbacks
You can use Oath
within single functions
// assignment style
var promise = new oath();
promise.then(successFn, errorFn);
myAsycFunction(function(err, result) {
if (err) promise.reject(err);
promise.resolve(result);
});
Or return them to ease chaining of callbacks
// return style
function doSomething(data) {
var promise = new oath();
// async stuff here
// promise should be returned immediately
return promise;
}
doSomething(data).then(successFn, errorFn);
function Oath (options) {
var self = this;
options = options || {};
this.pending = [];
this._options = {
parent: options.parent || null,
context: options.context || this
};