mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-15 04:23:12 +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;
|
||
|
}
|
||
|
}
|