1.0.0 • Published 10 months ago
@esfx/async-semaphore v1.0.0
@esfx/async-semaphore
The @esfx/async-semaphore
package provides the AsyncSemaphore
class, an async coordination primitive.
Overview
Installation
npm i @esfx/async-semaphore
Usage
import { AsyncSemaphore } from "@esfx/async-semaphore";
// create a semaphore that allows one participant
const semaphore = new AsyncSemaphore(1);
async function updateResource(updates) {
// Wait for a lock on the semaphore
await semaphore.wait();
try {
// Between the 'wait' above and the 'release' below,
// this function has exclusive access to a resource...
// Await something async, allowing other logic to
// execute. If some other event/timer/etc. calls
// 'updateResource' before this async operation
// finishes, they will be blocked at the 'wait' above.
await doSomethingAsync();
// We still have exclusive access even after resuming,
// so we can continue to use our exclusive access.
}
finally {
// Release the semaphore. The next waiter will
// be unblocked and will have the lock instead.
semaphore.release();
}
}
API
You can read more about the API here.
1.1.0-alpha.202307260322
10 months ago
1.1.0-alpha.202302091715
1 year ago
1.1.0-alpha.202306061406
11 months ago
1.1.0-alpha.202306061316
11 months ago
1.1.0-alpha.202306051228
11 months ago
1.1.0-alpha.202306080253
11 months ago
1.1.0-alpha.202302071935
1 year ago
1.1.0-alpha.202305082104
1 year ago
1.1.0-alpha.202211221509
1 year ago
1.1.0-alpha.202210252139
2 years ago
1.0.0
2 years ago
1.0.0-dev.7
2 years ago
1.0.0-pre.42
2 years ago
1.0.0-dev.8
2 years ago
1.0.0-pre.41
2 years ago
1.0.0-dev.5
2 years ago
1.0.0-pre.44
2 years ago
1.0.0-dev.6
2 years ago
1.0.0-pre.43
2 years ago
1.0.0-dev.4
2 years ago
1.0.0-prenative.0
2 years ago
1.0.0-prenative.1
2 years ago
1.0.0-dev.0
2 years ago
1.0.0-pre.40
2 years ago
1.0.0-pre.31
2 years ago
1.0.0-pre.33
2 years ago
1.0.0-pre.35
2 years ago
1.0.0-pre.34
2 years ago
1.0.0-pre.37
2 years ago
1.0.0-pre.36
2 years ago
1.0.0-pre.39
2 years ago
1.0.0-pre.38
2 years ago
1.1.0-alpha.202211291446
1 year ago
1.0.0-pre.30
3 years ago
1.0.0-pre.26
3 years ago
1.0.0-pre.25
3 years ago
1.0.0-pre.28
3 years ago
1.0.0-pre.29
3 years ago
1.0.0-pre.24
3 years ago
1.0.0-pre.23
3 years ago
1.0.0-pre.19
3 years ago
1.0.0-pre.17
3 years ago
1.0.0-pre.16
3 years ago
1.0.0-pre.13
5 years ago
1.0.0-pre.12
5 years ago
1.0.0-pre.11
5 years ago
1.0.0-pre.10
5 years ago
1.0.0-pre.9
5 years ago
1.0.0-pre.8
5 years ago
1.0.0-pre.7
5 years ago
1.0.0-pre.6
5 years ago
1.0.0-pre.5
5 years ago
1.0.0-pre.4
5 years ago
1.0.0-pre.3
5 years ago