以阮一峰的例子來看:var fs = require('fs');var readFile = function (fileName) { return new Promise(function (resolve, reject) { fs.readFile(fileName, function(error, data) { if (error) reject(error); resolve(data); }); });};var asyncReadFile = async function () { var f1 = await readFile('/etc/fstab'); var f2 = await readFile('/etc/shells'); console.log(f1.toString()); console.log(f2.toString());};在這個(gè)里面,如果我想每次把readFile里面的error打印出來,請(qǐng)問這個(gè)該怎么在async函數(shù)里面處理呢?
關(guān)于es7里面的async/await的一個(gè)疑問?
躍然一笑
2018-10-02 13:18:20