我在数组上使用 map 方法,以便设置间隔向 API 发送给定次数的请求(每个 timeInterval 都有不同的访问令牌)。我可以以某种方式创建一个函数来从外部清除这些间隔吗?
await Promise.all(
this.state.tokens
.map((token, index) => {
const driver = setInterval(() => {
if (decodedPolylines[index].length > 1) {
api.sendLocation(
token,
decodedPolylines[index][0][0].toString(),
decodedPolylines[index][0][1].toString()
);
} else {
api.clockInOut(
token,
'out',
decodedPolylines[index][0][0].toString(),
decodedPolylines[index][0][1].toString()
);
clearInterval(driver);
}
}, 1000);
})
);
慕斯王
Helenr
相关分类