import BLESDK from './ble' class taskQueue { list = [] isExecute = false overtime = null addTask(buffer) { if (!BLESDK.deviceInfo.state) return this.list.push(buffer) if (this.isExecute) return this.executeTask() } executeTask() { this.isExecute = !!this.list.length if (!this.list.length) return if (!BLESDK.deviceInfo.state) { this.list = [] this.isExecute = !!this.list.length return } BLESDK.writeBleValue(new Uint8Array([...this.list[0]]).buffer) this.list.shift() this.overtime = setTimeout(() => { this.stopOverTime() this.executeTask() }, 300) } stopOverTime() { clearTimeout(this.overtime) this.overtime = null } } export default new taskQueue()