mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-14 08:36:22 +08:00
34703a3b7d
https://github.com/toeverything/AFFiNE/blob/eyhn/feat/new-sync/packages/common/infra/src/workspace/engine/doc/README.md
21 lines
429 B
TypeScript
21 lines
429 B
TypeScript
export class AsyncLock {
|
|
private _lock = Promise.resolve();
|
|
|
|
async acquire() {
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
let release: () => void = null!;
|
|
const nextLock = new Promise<void>(resolve => {
|
|
release = resolve;
|
|
});
|
|
|
|
await this._lock;
|
|
this._lock = nextLock;
|
|
return {
|
|
release,
|
|
[Symbol.dispose]: () => {
|
|
release();
|
|
},
|
|
};
|
|
}
|
|
}
|