Skip to content

Commit

Permalink
feat: Improve request queue behavior (#718)
Browse files Browse the repository at this point in the history
  • Loading branch information
slugzero authored Jun 8, 2023
1 parent 2419e5c commit 68cfe55
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 49 deletions.
10 changes: 4 additions & 6 deletions src/controller/model/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ class Endpoint extends Entity {
debug.info(`Request Queue (${this.deviceIeeeAddress}/${this.ID}): send success`);
request.resolve(result);
} catch (error) {
debug.error(`Request Queue (${this.deviceIeeeAddress}/${this.ID}): send failed, expires in ` +
debug.info(`Request Queue (${this.deviceIeeeAddress}/${this.ID}): send failed, expires in ` +
`${(request.expires - now) / 1000} seconds`);
request.reject(error);
}
Expand Down Expand Up @@ -393,16 +393,14 @@ class Endpoint extends Entity {
}
return request.send();
}
// If we already have something queued, we queue directly to avoid
// messing up the ordering too much.
// If a send is already in progress or if this is a bulk message, we also queue directly.
if (this.hasPendingRequests() || request.sendPolicy === 'bulk' || this.sendInProgress) {
// If this is a bulk message, we queue directly.
if (request.sendPolicy === 'bulk') {
debug.info(logPrefix + `queue request (${this.pendingRequests.size} / ${this.sendInProgress})))`);
return this.queueRequest(request);
}

try {
debug.info(logPrefix + `send request (queue empty)`);
debug.info(logPrefix + `send request`);
return await request.send();
} catch(error) {
// If we got a failed transaction, the device is likely sleeping.
Expand Down
Loading

0 comments on commit 68cfe55

Please sign in to comment.