33 lines
620 B
JavaScript
Raw Normal View History

2025-04-16 18:15:18 +08:00
import BLESDK from './ble'
class taskQueue {
list = []
isExecute = false
overtime = null
addTask(buffer) {
this.list.push(buffer)
if (!this.isExecute) {
this.isExecute = true
this.executeTask()
}
}
executeTask() {
this.isExecute = !!this.list.length
if (!this.list.length) return
BLESDK.writeBleValue(new Uint8Array(['0x7b', ...this.list[0]]).buffer)
this.list.shift()
this.overtime = setTimeout(() => {
this.executeTask()
}, 1000)
}
stopOverTime() {
clearTimeout(this.overtime)
this.overtime = null
}
}
export default new taskQueue()