我编写了一个在循环(映射)中调用的函数,并且该函数使用了 Promise。现在,我希望该函数同步运行并在调用其下一个实例之前退出。
function t1(){
let arr1 = [1,2,3,4,5];
return Promise.map(arr1, (val) =>{
const params = {
"param1" : val1
};
return t2(params);
});
}
function t2(event){
return Promise.resolve()
.then({
//do something
//code doesn't reach here in sync manner. all five instance are invoked and then code reaches here for first instance and so on
})
.then({
//promise chaining. do something more
})
}
t2 被调用五次,但我希望每个实例只在实例返回值之前调用。目前它的行为不是那样,而是并行调用该函数五次。
由于项目限制,我无法使用 async/await。
手掌心
九州编程
四季花海
相关分类