Posted on 24/03/2012. By Pete Otaqui.
I’ve released bond – a simple Promises/A implementation. The only reasons to use this library rather than something like node-promise are that it can be used in a browser as well as nodejs, it supports multiple arguments for promise callbacks (this is actually why I wrote it) and it has a cool name.
Bond installation is extremely easy with npm by adding it to your package.json file and executing “npm install”.
It provides two equivalent options for usage “new bond.Deferred()” or “bond.defer()”. This returns a deferred object with the usual methods:
- my_deferred.resolve(arg1, …, argN)
- my_deferred.reject(arg1, …, argN)
- my_deferred.notify(arg1, …, argN)
- my_promise = my_deferred.promise() *
- my_promise.then(successFn, failureFn, progressFn)
- my_promise.done(successFn)
- my_promise.fail(failureFn)
- my_promise.progress(progressFn)
* nb – providing “promise()” as a method rather than a property violates the CommonJS Promises/A spec, but I’ve seen it elsewhere and prefer it.