mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-15 12:44:31 +03:00
15 lines
289 B
JavaScript
15 lines
289 B
JavaScript
|
export class Lock {
|
||
|
constructor() {
|
||
|
this.lockHolder = null;
|
||
|
}
|
||
|
|
||
|
async withLock(scope) {
|
||
|
while (this.lockHolder !== null) {
|
||
|
await this.lockHolder;
|
||
|
}
|
||
|
this.lockHolder = Promise.resolve(null).then(scope);
|
||
|
await this.lockHolder;
|
||
|
this.lockHolder = null;
|
||
|
}
|
||
|
}
|