thunkify源码分析:thunk 做了什么
Turn a regular node function into one which returns a thunk, useful for generator-based flow control such as co.
项目地址
https://github.com/visionmedia/node-thunkify
thunk 的理念
将执行函数和回调函数分开
thunkify
var thunkify = require('thunkify');
var fs = require('fs');
var read = thunkify(fs.readFile);
read('package.json', 'utf8')(function (err, str) {});
参考
https://codesandbox.io/s/thunk-function-forked-bzj4b?file=/src/App.js