Skip to content

Comments

fix: use cheaper async mutex in place of 1-queue#1587

Merged
Koenkk merged 2 commits intomasterfrom
asynx-mutex
Dec 13, 2025
Merged

fix: use cheaper async mutex in place of 1-queue#1587
Koenkk merged 2 commits intomasterfrom
asynx-mutex

Conversation

@Nerivec
Copy link
Collaborator

@Nerivec Nerivec commented Dec 10, 2025

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?

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 AsyncMutex class 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 AsyncMutex instead of Queue(1)
  • Adds comprehensive test coverage for the new AsyncMutex class

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>
Copy link
Owner

@Koenkk Koenkk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Feel free to merge

@Nerivec Nerivec marked this pull request as ready for review December 10, 2025 21:22
@Nerivec
Copy link
Collaborator Author

Nerivec commented Dec 10, 2025

Did you do a run with zstack just in case? (I already did with ember.)

@Koenkk
Copy link
Owner

Koenkk commented Dec 13, 2025

yes, looks good!

@Koenkk Koenkk merged commit 2a6900e into master Dec 13, 2025
4 checks passed
@Koenkk Koenkk deleted the asynx-mutex branch December 13, 2025 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants