Add mutex to packet lookup algorithm, fix incorrect next packet retrieval following packet lookup

This commit is contained in:
Vanilagy
2026-01-14 21:53:23 +01:00
parent 4a85aad012
commit 0719a17c85
4 changed files with 211 additions and 133 deletions
+13 -1
View File
@@ -248,15 +248,27 @@ export const isAllowSharedBufferSource = (x: unknown) => {
export class AsyncMutex {
currentPromise = Promise.resolve();
pending = 0;
async acquire() {
let resolver: () => void;
const nextPromise = new Promise<void>((resolve) => {
resolver = resolve;
let resolved = false;
resolver = () => {
if (resolved) {
return;
}
resolve();
this.pending--;
resolved = true;
};
});
const currentPromiseAlias = this.currentPromise;
this.currentPromise = nextPromise;
this.pending++;
await currentPromiseAlias;