Skip to content

Commit deaf83c

Browse files
Synchronize lock requests better.
1 parent 91db686 commit deaf83c

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

packages/web/src/worker/sync/WorkerClient.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,18 @@ export class WorkerClient {
6969
* When the client tab is closed, its lock will be returned. So when the shared worker attempts to acquire the lock,
7070
* it can consider the connection to be closed.
7171
*/
72-
addLockBasedCloseSignal(name: string) {
72+
async addLockBasedCloseSignal(name: string) {
7373
if (!this.resolvedPortPromise) {
7474
// The init logic above is actually synchronous, so this should not happen.
7575
this.sync.broadCastLogger.warn('addLockBasedCloseSignal called before port promise registered');
7676
} else {
77-
this.resolvedPortPromise.then((wrappedPort) => {
78-
/**
79-
* The client registered a navigator lock. We now can guarantee detecting if the client has closed.
80-
* E.g. before this point: It's possible some ports might have been created and closed before the
81-
* lock based close signal is added. We should not trust those ports.
82-
*/
83-
wrappedPort.isProtectedFromClose = true;
84-
});
77+
const wrappedPort = await this.resolvedPortPromise;
78+
/**
79+
* The client registered a navigator lock. We now can guarantee detecting if the client has closed.
80+
* E.g. before this point: It's possible some ports might have been created and closed before the
81+
* lock based close signal is added. We should not trust those ports.
82+
*/
83+
wrappedPort.isProtectedFromClose = true;
8584
}
8685
getNavigatorLocks().request(name, async () => {
8786
await this.removePort();

0 commit comments

Comments
 (0)