Skip to content
/ yil Public

YilJS - A library to convert callback'd functions into synchronous yields

License

Notifications You must be signed in to change notification settings

Tombert/yil

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Yil

YilJS - A library to convert callback'd functions into synchronous yields

Mindset

You just learned about the yield keyword in ECMAScript 6, you want to play it, but drat, you're stuck with a library that depends on the last argument being a callback. What a drag.

Yil helps skirt this by creating an easy wrapper to write synchronous code.

Requirements

Technically, this library doesn't contain any code that won't work in Node 0.8. However, since the whole point is to generate yield-friendly code, you're probably going to want Node 0.11 or later with the --harmony flag.

How to Use

Ah, now the real fun.

To use Yil with a function where the last argument is a callback:

var myAsyncFunction = function(arg1, arg2, callback){
    //do stuff
    callback(data); 
}

var myYieldFunction = function(){
    var thing = yield yil.callback(myAsyncFunction, arg1, arg2); 
}

If you need to specify a specific scope, write it like this:

var thing = yield yil.callback({scope:this, func: myAsyncFunction}, arg1, arg2);

About

YilJS - A library to convert callback'd functions into synchronous yields

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published