Wait for the critical section to become available and execute a function.
A function which will be executed exclusively in the critical section.
A promise which is resolved with the (eventually) returned
value by func
. Effectively, once the critical section has
been entered, Promise.resolve(func())
is returned.
Especially if func
returns a Thenable, by the semantics of
Promise.resolve
, this Thenable is adopted as the new Promise.
In other words, it is impossible to make
criticalSection.do(...)
resolve to a Promise, i.e.
await criticalSection.do(...)
be a Promise.
Generated using TypeDoc
A non-reentrant critical section offering execution of (async) functions therein.
Effectively, it is a wrapper around ISemaphore, also accommodating easy-to-miss edge cases when errors are thrown or Promises rejected.
Simple usage:
Exceptions in a synchronous exclusive function:
Rejections in an asynchronous exclusive function: