2 回答
TA贡献1805条经验 获得超10个赞
已实现~
let arr = [] function sendPost(text) { return new Promise((resolve) => { setTimeout(() => { arr.push({ text, time: new Date() }) resolve(text) }, 1000) }) } let text1 = ['a1', 'a2', 'a3', 'a4'] let text2 = ['b1', 'b2', 'b3', 'b4'] text1.forEach(v => sendPost(v)) const promiseArr = text2.map(v => ()=>sendPost(v)) promiseArr.reduce((prevPromise, nextPromise) => { return prevPromise.then(()=>nextPromise()) }, Promise.resolve())
TA贡献1820条经验 获得超10个赞
没看懂你的意思,实现效果是类似的const text1=['a1','a2','a3','a4']const text2=['b1','b2','b3','b4']let arr = []function sendPost(text1,text2){ return new Promise((resolve)=>{
text1.forEach(item=>{
arr.push(`${item} ${new Date()}`)
})
resolve([arr,text2])
})
}
sendPost(text1,text2).then(res=>{ console.log(res[0])
return res[1]
}).then(res=>{ let currentTime = 1000
res.forEach(item=>{
timer =setTimeout(()=>{ console.log(`${item} ${new Date()}`)
},currentTime)
currentTime +=1000
})
})
- 2 回答
- 0 关注
- 553 浏览
添加回答
举报