gpt4 book ai didi

node.js - 如何将 .then 方法制作为 async.waterfall Node js

转载 作者:太空宇宙 更新时间:2023-11-04 01:37:32 24 4
gpt4 key购买 nike

我想将 .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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com