co-thunkify
v0.0.1
Published
Turn regular node function into a thunk for `co`.
Downloads
23
Maintainers
Readme
[co-thunkify][npm.lnk] - 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
[![npm][npm.png]][npm.lnk] [npm.lnk]: https://www.npmjs.org/package/co-thunkify [npm.png]: https://nodei.co/npm/co-thunkify.png
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