我想将 .then Promise 方法更改为 async.waterfall
var readfile = require('./app.js')
var fileName = 'batch1.txt'
var fileName1 = 'batch2.txt'
readfile(fileName).then((message) => {
readfile(fileName1).then((message1) => {
console.log(message);
console.log(message1);
});
});
最佳答案
试试这个:
var readfile = require('./app.js')
var fileName = 'batch1.txt'
var fileName1 = 'batch2.txt'
readfile(fileName)
.then(() => readfile(fileName1) )
.then( (msg)=> console.log(msg));
或者您可以使用Promise.all
Promise.all([ readfile(fileName), readfile(fileName1) ]).then( ( results // Array ) =>{
console.log(results[0]); // result of first promise
console.log(results[1]); // result of second promise
});
关于node.js - 如何将 .then 方法制作为 async.waterfall Node js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54058943/