// 循环同步任务
async function loopSyncTask() {
await setInterval(() => {
let authedStore = storage.getItem('authedStore')
log.info(
'====================== sync message start ======================'
)
let syncResult = Object.keys(authedStore).map(async (key) => {
let result = await syncMessage({
host: authedStore[key].host,
token: authedStore[key].token,
userInfo: authedStore[key].storeName,
})
// 这里能打印到result
return result
})
log.info(JSON.stringify(syncResult)) //想要这里打印在中间,但是结果是[{},{}]
log.info(
'====================== sync message end ======================'
)
}, 10000)
}
实际效果是这样的
======================= sync message start ======================
[{},{}]
====================== sync message end ======================
......你这明显就是错误的写法呀。
实际上代码执行到你的
异步代码并没有执行完。所以这里获取的是空。
建议优化语法