hardhat
Version:
Hardhat is an extensible developer tool that helps smart contract developers increase productivity by reliably bringing together the tools they want.
47 lines • 1.29 kB
JavaScript
/**
* A class that implements an asynchronous mutex (mutual exclusion) lock.
*
* The mutex ensures that only one asynchronous operation can be executed at a time,
* providing exclusive access to a shared resource.
*/
export class AsyncMutex {
/**
* Acquires the mutex, running the provided function exclusively,
* and releasing it afterwards.
*
* @param f The function to run.
* @returns The result of the function.
*/
async exclusiveRun(f) {
const release = await this.
try {
return await f();
}
finally {
await release();
}
}
/**
* Acquires the mutex, returning a function that releases it.
*/
async
if (!this.
this.
return async () => {
this.
const next = this.
if (next !== undefined) {
next();
}
};
}
return new Promise((resolve) => {
this.
resolve(this.
});
});
}
}
//# sourceMappingURL=async-mutex.js.map