如何使用async
/await
來實現以下目標?async/await如何與forEach一起使用?
self.onmessage = event => {
// async stuff in forEach needs to finish
event.data.search.split(',').forEach((s, i) => {
db.get('customers').then(doc => {
...
})
})
// before getting here
}
也許[上文檔SO(http://stackoverflow.com/documentation/javascript/925/async異步/等待/ 7746 /循環與異步 - 等待#t = 201703052353271956842)將有助於... – rasmeister
異步/等待將使這個代碼不必要的複雜 - 總是使用最好的工具,而不一定是最新的閃亮的小工具:p –
其實,'await/async'根本不會幫忙 –