confetti

Promise decorator built on top of rsvp.js.

Confetti ========

Confetti is a promise decorator built on top of rsvp.js. With Confetti, you can easily define promise constructors that have custom functions attached to the constructor's prototype. The custom functions get wrapped in a way that allows them to be called within the framework of promises. It's quite cool.

The documentation for this project is lacking and I plan on adding much more thorough documentation as soon as I can. Until then, if you have any questions about Confetti, open up an issue or contact me through whatever means works for you.

$ npm install confetti
var confetti = require('confetti');

Returns a promise constructor with each function contained in functions added to its prototype. Before being added to the constructor's prototype, each function contained in functions will be wrapped to work within the promise framework.

Confetti works with both sync and async functions. In order to determine whether or not the function being dealt with is sync or async, Confetti relies on the function's signature. If the function's signature contains 1 more parameter then it's being called with, Confetti will assume the function is asynchronous and that the missing argument is the callback function.

Note that Confetti is very picky about function signatures. Bad things will happen when the number of arguments a function is called with doesn't match up with the number of formal parameters. The one exception to this rule is for async functions. With async functions, you should omit the callback argument when calling them.

var confetti = require('confetti');
 
var Promise = confetti.define({ 
  syncfunction(adjective) { 
    return 'Sync functions are ' + adjective + '!';
  },
  asyncfunction(adjectivecb) {
    process.nextTick(function() {
      cb(null, 'Async functions are ' + adjective + '!');
    });
  }
});
 
var promise = new Promise();
 
promise
.async('hip')
.value(function(result) { console.log(result); })
.sync('old school')
.value(function(result) { console.log(result); })
.error(function(err) { console.log('error is bad'); });
 
promise.resolve();
Async functions are hip!
Sync functions are old school!
$ cd confetti
$ npm test

Found a bug? Create an issue on GitHub.

https://github.com/jharding/confetti/issues

For transparency and insight into the release cycle, releases will be numbered with the follow format:

<major>.<minor>.<patch>

And constructed with the following guidelines:

  • Breaking backwards compatibility bumps the major
  • New additions without breaking backwards compatibility bumps the minor
  • Bug fixes and misc changes bump the patch

For more information on semantic versioning, please visit http://semver.org/.

Copyright (c) 2012 Jake Harding
Licensed under the MIT License.