const sendDataCycle = async() => {
try {
const data = await getData() // get data from DB
io.send(data) // send by socket.io
setTimeout(() => {
sendDataCycle() // send again after 10 s
}, 10000)
} catch (err) {
setTimeout(() => {
sendDataCycle() // if error - send again after 20 s or else
}, 20000)
}
}
sendDataCycle() // run cycle
1条答案
按热度按时间ljo96ir51#
您需要使用类似于以下内容的内容:
请不要使用
setInterval
函数。