thunkify源码分析:thunk 做了什么

Turn a regular node function into one which returns a thunk, useful for generator-based flow control such as co.
更新于: 2021-12-19 12:57:29

项目地址

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