改用更精确的定时器

This commit is contained in:
洛洛希雅 2024-05-08 13:52:13 +08:00
parent b720bf4b24
commit 37b00d8d17

View File

@ -88,7 +88,12 @@ async function publish() {
} }
publishing.startTime = Date.now() publishing.startTime = Date.now()
publishing.count = list.length publishing.count = list.length
while (!exit) { //
const interval = setInterval(() => {
if (exit) {
clearInterval(interval)
return
}
const item = next() const item = next()
publishing.lastTime = Date.now() publishing.lastTime = Date.now()
if (item[0]?.content[0]) { if (item[0]?.content[0]) {
@ -103,9 +108,7 @@ async function publish() {
const json = JSON.stringify(item) const json = JSON.stringify(item)
mqttClient!.publish(topic, json, {}) mqttClient!.publish(topic, json, {})
}, 100)
await delay(100)
}
})().catch((e) => console.error(e)) })().catch((e) => console.error(e))
} }
</script> </script>