0.0.1 • Published 9 years ago
co-thunkify v0.0.1
co-thunkify - async await thunkify for co
Turn a regular node function into one which returns a thunk, useful for generator-based flow control.
Installation
$ npm install co-thunkify
Examples
read file example
var thunkify = require('co-thunkify');
var fs = require('fs');
// read file
var readFile = thunkify(fs.readFile);
readFile('package.json', 'utf8')(function (err, buff) {
var str = buff.toString();
// str...
});
sleep example
var thunkify = require('co-thunkify');
// sleep
var sleep = thunkify(function (ms, cb) {
setTimeout(cb, ms);
});
console.log('sleep start...');
sleep(3000)(function () {
console.log('3 seconds later...');
});
sync and async example
License
MIT