resolver-macro
This sweet.js macro will help you turn any standard callback-based function into a promise, using whichever promise library you want.
Example
Here's an example using when and the standard fs.readFile
command:
when;
Getting Started
To use the macro, take a look at the sweet.js project, or setup a grunt task using something like grunt-sweet.js. You can then just install this module and require it when running sweet.js.
If you are totally new to macros, I recommend reading this excellent article:
Writing Your First Sweet.js Macro by James Long
Usage
The resolver
macro will match the following pattern:
And expand it to:
{
This allows you to wrap that resolver function in any promise library you want. It will take
any arguments in ARGS...
and pass them to FUNCTION
, and then add on the callback handling
function for you.