promiscuous is a JavaScript promise/deferred implementation, implementing the Promises/A+ spec.
It strives to be minimal (0.8kb minified / 0.45kb gzipped) and fast.
First, install promiscuous with npm.
$ npm install promiscuous
Then, include promiscuous in your code file.
var promiscuous = require('promiscuous');
Include promiscuous in your HTML file.
<script src="promicuous-browser.js"></script>
var one = promiscuous.resolve("one");
one.then(console.log);
/* one */
var none = promiscuous.reject("error");
none.then(console.log, console.error);
/* error */
function promiseSomething(something) {
var defer = promiscuous.deferred();
setTimeout(function () {
if (something)
defer.resolve(something);
else
defer.reject("nothing");
}, 1000);
return defer.promise;
}
promiseSomething("something").then(console.log, console.error);
/* something */