fix: use cheaper async mutex in place of 1-queue#1587
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR replaces the Queue(1) implementation with a new, lighter AsyncMutex class for mutual exclusion of asynchronous operations. The new implementation avoids the overhead of job object creation and filtering operations present in the original Queue class, using a simpler promise-based approach with a queue of resolver functions.
Key changes:
- Introduces a new
AsyncMutexclass that provides mutual exclusion for async operations using a locked flag and a queue of promise resolvers - Updates six adapter implementations (zigate, zboss uart, zboss driver, z-stack, ezsp uart, ezsp driver, ember) to use
AsyncMutexinstead ofQueue(1) - Adds comprehensive test coverage for the new
AsyncMutexclass
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/utils/async-mutex.ts | New lightweight async mutex implementation using private fields and promise-based queuing |
| test/utils.test.ts | Adds test coverage for AsyncMutex with fake timers to verify mutex behavior and queue clearing |
| src/adapter/zigate/driver/zigate.ts | Replaces Queue(1) with AsyncMutex, updates execute() calls to run() |
| src/adapter/zboss/uart.ts | Replaces Queue(1) with AsyncMutex, updates execute() calls to run() |
| src/adapter/zboss/driver.ts | Replaces Queue() with AsyncMutex, updates execute() calls to run() |
| src/adapter/z-stack/znp/znp.ts | Replaces Queue() with AsyncMutex, updates execute() calls to run() |
| src/adapter/ezsp/driver/uart.ts | Replaces Queue(1) with AsyncMutex, updates execute() calls to run() |
| src/adapter/ezsp/driver/ezsp.ts | Replaces Queue() with AsyncMutex, updates execute() calls to run() |
| src/adapter/ember/ezsp/ezsp.ts | Replaces Queue(1) with AsyncMutex, updates execute() calls to run() |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Collaborator
Author
|
Did you do a run with zstack just in case? (I already did with ember.) |
Owner
|
yes, looks good! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Should be much cheaper/faster to run than
Queue(1), no job object creation, no filtering needed, simple shift op.@Koenkk what do you think?