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], {});
}
catch (err) {
if (err.message === 'In Progress') {
setTimeout(() => this.write(data, retry), 1000);
return;
}
console.log('plejd-ble: write failed ' + err);
setTimeout(async () => {
await this.init();
@ -425,12 +430,22 @@ class PlejdService extends EventEmitter {
console.log('startWriteQueue()');
clearInterval(this.writeQueueRef);
this.writeQueueRef = setInterval(async () => {
while (this.writeQueue.length > 0) {
const data = this.writeQueue.pop();
await this.write(data);
}
}, 400);
this.writeQueueRef = setTimeout(runWriteQueue, 400);
// this.writeQueueRef = setInterval(async () => {
// while (this.writeQueue.length > 0) {
// const data = this.writeQueue.pop();
// await this.write(data);
// }
// }, 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) {