Skip to content

Web Lock API instead of Mutex - #44

Merged
langsamu merged 7 commits into
mainfrom
no-mutex
Sep 22, 2026
Merged

langsamu merged 7 commits into
mainfrom
no-mutex

Conversation

@langsamu

@langsamu langsamu commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

@langsamu langsamu changed the title Wwb Lock API instead of Mutex Web Lock API instead of Mutex Sep 18, 2026
@langsamu
langsamu marked this pull request as ready for review September 18, 2026 14:36

@jeswr jeswr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Only the documentation comment is directly relevant to this PR. The rest can be applied separately in follow ups.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks like NodeJS support for the Web Lock API was added in Node 24. Node 22 is in maintenance until April 2027 - we should therefore document that Node v24 is the minimum supported node version.

I'd also double check they haven't backported it before writing the exact version.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good point, thx.

d83ffef

Comment thread src/AuthorizationCodeFlow.ts Outdated
Comment on lines +182 to +183
const {promise: responseFromPopup, reject: cancelCodeRequest, resolve: respondWithCode} = Promise.withResolvers<string>()
signal.throwIfAborted()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not throw before creating the promise.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Indeed.

2822a02

Comment thread src/IdpPicker.ts
this.#dialog.addEventListener("close", onClose, onlyOnce)

return await promise
return await promise

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
return await promise
return promise

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I would rather not.

Really, both asyncs and both awaits in this method could be eliminated because nothing in the method itself uses the value of the promises.

But instead I choose to spell out both pairs because it seems clearer to me what is happening. In general I prefer to await all promises rather than rely on the reader to untangle them.

Comment thread src/WebIdPicker.ts
this.#dialog.addEventListener("close", onClose, onlyOnce)

return await promise
return await promise

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
return await promise
return promise

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

As above.

// One flow at a time, fellas
using _ = await this.#mutex.acquire()
return await navigator.locks.request("AuthorizationCodeFlow.getCode", async _ => {
this.#authorizationUri = authorizationUri

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Probably best to do this after the check of whether the signal is aborted.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Indeed.

85332ae

@langsamu
langsamu merged commit c3c22d5 into main Sep 22, 2026
5 checks passed
@langsamu
langsamu deleted the no-mutex branch September 22, 2026 09:18
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