Covenant is a tight and performant Promises/A+ implementation written in Coffeescript. Covenant passes the Promises/A+ Test Suite (Version 1.1).
Download it, clone it, or
npm install wizardwerdna/covenant
Covenant has no dependencies, but does use process.nextTick, found in modern Browsers. If process.nextTick is not a function, Covenant falls back to setImmediate, and then to setTimeout. If you are using ancient browsers, it is highly recommended that you use a shim to implement (fake) nextTick and/or setImmediate.
// load the coffeescript compiler (unless running precompiled version)// and then follow up with obvious variations of the coffeescript belowrequire'coffee-script';
# get the Promise classCovenant = require'covenant'Covenant# create a new pending promisecovenant =# fulfill itcovenantfulfillvalue# reject itcovenantrejectreason# schedule asynchronous handerscovenantthen onFulfilledonRejected
I set out to write Covenant, just for myself, so to achieve a better understanding of the nuances of the Promise pattern. The Promises/A+ specification seemed elegant, but I couldn't seem to grok it without more. Reading the code of various compliant mplementations was helpful, but I still didn't seem to own it. I began the experiment by "cowboy" coding a first set, using the test suite to verify that things were working. Finally, I discarded that code as one to throw away, and rebuilt it in pure BDD red-green-refactor style.
Having a well-understood testbed for promises, I will probably extend covenant to a more full-featured implementation.
MIT License, Copyright (c) 2013 Andrew C. Greenberg (email@example.com)