reworked write queue
This commit is contained in:
parent
b8f87d47a5
commit
5e11f39c86
1 changed files with 21 additions and 6 deletions
|
|
@ -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) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue