co-thunkify

0.0.1 • Public • Published

co-thunkify - async await thunkify for co

Turn a regular node function into one which returns a thunk, useful for generator-based flow control.

Japanese version/■日本語版はこちら■

Installation

$ npm install co-thunkify

npm

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

/co-thunkify/

    Package Sidebar

    Install

    npm i co-thunkify

    Weekly Downloads

    2

    Version

    0.0.1

    License

    MIT

    Last publish

    Collaborators

    • lightspeedc