reworked write queue

This commit is contained in:
Marcus Westin 2020-03-03 15:59:10 +01:00
parent b8f87d47a5
commit 5e11f39c86

View file

@ -362,6 +362,11 @@ class PlejdService extends EventEmitter {
await this.characteristics.data.WriteValue([...encryptedData], {}); await this.characteristics.data.WriteValue([...encryptedData], {});
} }
catch (err) { catch (err) {
if (err.message === 'In Progress') {
setTimeout(() => this.write(data, retry), 1000);
return;
}
console.log('plejd-ble: write failed ' + err); console.log('plejd-ble: write failed ' + err);
setTimeout(async () => { setTimeout(async () => {
await this.init(); await this.init();
@ -425,12 +430,22 @@ class PlejdService extends EventEmitter {
console.log('startWriteQueue()'); console.log('startWriteQueue()');
clearInterval(this.writeQueueRef); clearInterval(this.writeQueueRef);
this.writeQueueRef = setInterval(async () => { this.writeQueueRef = setTimeout(runWriteQueue, 400);
while (this.writeQueue.length > 0) { // this.writeQueueRef = setInterval(async () => {
const data = this.writeQueue.pop(); // while (this.writeQueue.length > 0) {
await this.write(data); // const data = this.writeQueue.pop();
} // await this.write(data);
}, 400); // }
// }, 400);
}
async runWriteQueue() {
while (this.writeQueue.length > 0) {
const data = this.writeQueue.pop();
await this.write(data, true);
}
this.writeQueueRef = setTimeout(runWriteQueue, 400);
} }
async _processPlejdService(path, characteristics) { async _processPlejdService(path, characteristics) {