callback改成promise
let promisify = (fn, receiver) => { return (...args) => { return new Promise((resolve, reject) => { fn.apply(receiver, [...args, (err, res) => { return err ? reject(err) : resolve(res); }]); }); }; };
var fs = require("fs"); var readFilePromise = promisify(fs.readFile, fs); //包装为 Promise 接口 readFilePromise("foo.json", "utf8").then(function(content){ //正常情况 }).catch(function(err){ //异常情况 })