You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+68-28Lines changed: 68 additions & 28 deletions
Original file line number
Diff line number
Diff line change
@@ -38,7 +38,7 @@ If your use case requires a concurrency of 1, consider using the lock variant of
38
38
-__Graceful & Deterministic Teardown :hourglass_flowing_sand:__: Await the completion of all currently executing jobs via the `waitForAllExecutingJobsToComplete` method. This guarantees **smooth resource cleanup**, making it well-suited for production environments (e.g., `onModuleDestroy` in NestJS) and maintaining a clean state between unit tests.
39
39
-__High Efficiency :gear:__: All state-altering operations have a constant time complexity, O(1).
40
40
-__Comprehensive documentation :books:__: The class is thoroughly documented, enabling IDEs to provide helpful tooltips that enhance the coding experience.
41
-
-__Robust Error Handling__: Uncaught errors from background jobs triggered by `startExecution` are captured and can be accessed using the `extractUncaughtErrors` method.
41
+
-__Robust Error Handling :warning:__: Uncaught errors from background jobs triggered by `startExecution` are captured and can be accessed using the `extractUncaughtErrors` method.
42
42
-__Metrics :bar_chart:__: The class offers various metrics through getter methods, such as `amountOfCurrentlyExecutingJobs`, providing insights into the semaphore's current state. These metrics can be used for periodic logging or to collect statistics from real-world usage.
43
43
-__Tests :test_tube:__: Fully covered by rigorous unit tests.
44
44
- Self-explanatory method names.
@@ -100,29 +100,29 @@ Note: method `waitForAllExecutingJobsToComplete` can be used to perform post-pro
console.info(`Finished aggregating data from ${sensorCount} IoT sensors`);
126
126
}
127
127
128
128
/**
@@ -136,46 +136,84 @@ async function handleDataAggregation(sensorUID): Promise<void> {
136
136
}
137
137
```
138
138
139
+
The `waitForAvailability` method is ideal for scenarios where you prefer a `while` loop structure or need to defer fetching the next job's metadata **until** the semaphore confirms that at least one execution slot is available.
140
+
This pattern is especially useful when you want to minimize the **delay between acquiring job metadata and dispatching its execution**, ensuring timely and efficient job handling.
141
+
Below is a tailored example illustrating this approach:
console.info(`Finished aggregating data from ${sensorCount} IoT sensors`);
174
+
}
175
+
```
176
+
139
177
If jobs might throw errors, you don't need to worry about these errors propagating to the event loop and potentially crashing the application. Uncaught errors from jobs triggered by `startExecution` are captured by the semaphore and can be safely accessed for post-processing purposes (e.g., metrics).
140
178
Refer to the following adaptation of the above example, now utilizing the semaphore's error handling capabilities:
Copy file name to clipboardExpand all lines: package.json
+7-4Lines changed: 7 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
{
2
2
"name": "zero-backpressure-semaphore-typescript",
3
-
"version": "3.1.2",
3
+
"version": "3.1.3",
4
4
"description": "A modern Promise-semaphore for Node.js projects, enabling users to limit the number of concurrently executing promises. Offering backpressure control for enhanced efficiency, utilizing a communicative API that signals availability, promoting a just-in-time approach. Additionally, it incorporates mechanisms for graceful termination and error handling, making it suitable for complex scenarios.",
0 commit comments