1.0.0 • Published 2 years 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
2 years ago
1.1.0-alpha.202302091715
2 years ago
1.1.0-alpha.202306061406
2 years ago
1.1.0-alpha.202306061316
2 years ago
1.1.0-alpha.202306051228
2 years ago
1.1.0-alpha.202306080253
2 years ago
1.1.0-alpha.202302071935
2 years ago
1.1.0-alpha.202305082104
2 years ago
1.1.0-alpha.202211221509
3 years ago
1.1.0-alpha.202210252139
3 years ago
1.0.0
3 years ago
1.0.0-dev.7
3 years ago
1.0.0-pre.42
3 years ago
1.0.0-dev.8
3 years ago
1.0.0-pre.41
3 years ago
1.0.0-dev.5
3 years ago
1.0.0-pre.44
3 years ago
1.0.0-dev.6
3 years ago
1.0.0-pre.43
3 years ago
1.0.0-dev.4
3 years ago
1.0.0-prenative.0
3 years ago
1.0.0-prenative.1
3 years ago
1.0.0-dev.0
3 years ago
1.0.0-pre.40
3 years ago
1.0.0-pre.31
3 years ago
1.0.0-pre.33
3 years ago
1.0.0-pre.35
3 years ago
1.0.0-pre.34
3 years ago
1.0.0-pre.37
3 years ago
1.0.0-pre.36
3 years ago
1.0.0-pre.39
3 years ago
1.0.0-pre.38
3 years ago
1.1.0-alpha.202211291446
3 years ago
1.0.0-pre.30
4 years ago
1.0.0-pre.26
4 years ago
1.0.0-pre.25
4 years ago
1.0.0-pre.28
4 years ago
1.0.0-pre.29
4 years ago
1.0.0-pre.24
4 years ago
1.0.0-pre.23
4 years ago
1.0.0-pre.19
4 years ago
1.0.0-pre.17
4 years ago
1.0.0-pre.16
4 years ago
1.0.0-pre.13
6 years ago
1.0.0-pre.12
6 years ago
1.0.0-pre.11
6 years ago
1.0.0-pre.10
6 years ago
1.0.0-pre.9
6 years ago
1.0.0-pre.8
6 years ago
1.0.0-pre.7
6 years ago
1.0.0-pre.6
6 years ago
1.0.0-pre.5
6 years ago
1.0.0-pre.4
6 years ago
1.0.0-pre.3
6 years ago