mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-27 19:03:46 +02:00
Add mutex to packet lookup algorithm, fix incorrect next packet retrieval following packet lookup
This commit is contained in:
+13
-1
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user