mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-15 17:50:51 +00: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;
|
||
|
}
|
||
|
}
|