Skip to content

Commit 8b7f1d6

Browse files
committed
Bump version to v1.0.1: README enhancements, adding a table of contents
1 parent b09c493 commit 8b7f1d6

File tree

3 files changed

+38
-14
lines changed

3 files changed

+38
-14
lines changed

README.md

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,19 @@ It controls the complete lifecycle of tasks and their promises by:
99

1010
This class is particularly well-suited for scenarios that demand precise control over the execution and termination of asynchronous tasks. It is an extension of the [delayed-async-task](https://www.npmjs.com/package/delayed-async-task) package, offering broader capabilities for managing multiple tasks.
1111

12-
## Key Features :sparkles:
12+
## Table of Contents
13+
14+
* [Key Features](#key-features)
15+
* [API](#api)
16+
* [Execution Status Getters](#execution-status-getters)
17+
* [Use Case Example: Security Incident Response System](#use-case-example)
18+
* [Design Decision: Task Manager per Use Case](#design-decision)
19+
* [Graceful and Deterministic Termination](#graceful-termination)
20+
* [Non-Persistent Scheduling](#non-persistent-scheduling)
21+
* [Error Handling](#error-handling)
22+
* [License](#license)
23+
24+
## Key Features :sparkles:<a id="key-features"></a>
1325

1426
* __Modern Substitute for Javascript's 'setTimeout'__: Specifically designed for scheduling asynchronous tasks, i.e., callbacks that return a Promise.
1527
* __Execution Status Getters__: Allows users to check the task's execution status, helping to prevent potential race conditions.
@@ -23,7 +35,7 @@ This class is particularly well-suited for scenarios that demand precise control
2335
* ES2020 Compatibility.
2436
* TypeScript support.
2537

26-
## API :globe_with_meridians:
38+
## API :globe_with_meridians:<a id="api"></a>
2739

2840
The `DelayedAsyncTasksManager` class provides the following methods:
2941

@@ -39,19 +51,21 @@ The `DelayedAsyncTasksManager` class provides the following methods:
3951

4052
If needed, refer to the code documentation for a more comprehensive description of each method.
4153

42-
## Execution Status Getters :mag:
54+
## Execution Status Getters :mag:<a id="execution-status-getters"></a>
4355

4456
The `DelayedAsyncTasksManager` class provides the following getter methods to reflect the current manager's state:
4557

4658
* __pendingTasksCount__: The number of tasks in a pending state. i.e., managed tasks which did not start their execution yet.
4759
* __currentlyExecutingTasksCount__: The number of tasks managed by this instance that are currently executing, i.e., tasks that are neither pending nor completed.
4860
* __uncaughtErrorsCount__: The number of uncaught task errors, that are currently stored by the instance. These errors have not yet been extracted using `extractUncaughtErrors`. Knowing the number of uncaught errors allows users to decide whether to process them immediately or wait for further accumulation.
4961

50-
## Use Case Example: Security Incident Response System :man_technologist:
62+
To eliminate any ambiguity, all getter methods have **O(1)** time and space complexity, meaning they do **not** iterate through all currently managed tasks with each call. The metrics are maintained by the tasks themselves.
5163

52-
Consider a Security Incident Response System, that schedules delayed actions such as disabling compromised user accounts, revoking access tokens, or blocking suspicious IP addresses. Each task is associated with a unique key (e.g., user ID, token ID), enabling security teams to **delay and manage responses based on evolving threat intelligence**. Tasks can be **canceled or adjusted if the threat is mitigated** before the action is triggered.
64+
## Use Case Example: Security Incident Response System :man_technologist:<a id="use-case-example"></a>
5365

54-
In real-world scenarios, responses to security incidents are often immediate to minimize damage. However, delayed tasks could be applicable in cases where actions aren't taken immediately **to gather more context or prevent premature actions** based on incomplete information. For example, the delay could be used to notify administrators or confirm suspicious behavior before taking disruptive measures, like blocking access or disabling accounts.
66+
Consider a Security Incident Response System, that schedules delayed actions such as disabling compromised user accounts, revoking access tokens, or blocking suspicious IP addresses. Each task is associated with a unique key (e.g., user ID, token ID), enabling security teams to **delay and manage responses** based on evolving threat intelligence. Tasks can be **canceled or adjusted** if the threat is mitigated before the action is triggered.
67+
68+
In real-world scenarios, responses to security incidents are often immediate to minimize damage. However, delayed tasks could be applicable in cases where actions aren't taken immediately to gather more context or prevent premature actions based on incomplete information. For example, the delay could be used to notify administrators or confirm suspicious behavior before taking disruptive measures, like blocking access or disabling accounts.
5569

5670
Please note that this example is overly simplified. Real-world usage examples can be more complex, often involving persistency and synchronization with external resources.
5771

@@ -111,7 +125,17 @@ class IncidentResponseSystem {
111125
}
112126
```
113127

114-
## Graceful and Deterministic Termination :hourglass:
128+
## Design Decision: Task Manager per Use Case<a id="design-decision"></a>
129+
130+
Separating code into small, single-responsibility building blocks improves testability and readability. While it may seem simpler to use a single scheduler as a 'single source of truth' for all task types, this approach can lead to increased complexity as the application scales.
131+
132+
For instance, the *Incident Response System* code example above could benefit from employing two task managers instead of one:
133+
* Enable Account Manager
134+
* Disable Account Manager
135+
136+
One benefit is the ability to gather operation-specific metrics, such as periodically sampling the number of pending Disable Account actions through the `pendingTasksCount` getter.
137+
138+
## Graceful and Deterministic Termination :hourglass:<a id="graceful-termination"></a>
115139

116140
In the context of asynchronous tasks and schedulers, graceful and deterministic termination is **often overlooked**. `DelayedAsyncTasksManager` provides an out-of-the-box mechanism to await the completion of an asynchronous task that has already started but has not yet finished, using either the `awaitTaskCompletion` or `awaitCompletionOfAllCurrentlyExecutingTasks` method.
117141

@@ -207,13 +231,13 @@ class Component {
207231

208232
Another scenario where this feature is highly recommended is when a schedule might be aborted, such as in an abort-and-reschedule situation. If the task is currently executing (which can be checked via the `isExecuting` method), it cannot be aborted. In such cases, you can ignore the reschedule request, await the current execution to complete using `awaitTaskCompletion`, or implement any other business logic that suits your requirements.
209233

210-
## Non-Persistent Scheduling
234+
## Non-Persistent Scheduling<a id="non-persistent-scheduling"></a>
211235

212236
This component features non-durable scheduling, which means that if the application crashes or goes down, scheduling stops.
213237

214238
If you need to guarantee durability over a multi-node deployment, consider other custom-made solutions for that purpose.
215239

216-
## Error Handling :warning:
240+
## Error Handling :warning:<a id="error-handling"></a>
217241

218242
Unlike `setTimeout` in Node.js, where errors from rejected promises propagate to the event loop and trigger an `uncaughtRejection` event, this package offers robust error handling:
219243

@@ -222,6 +246,6 @@ Unlike `setTimeout` in Node.js, where errors from rejected promises propagate to
222246

223247
Ideally, a delayed task should handle its own errors and **avoid** throwing uncaught exceptions.
224248

225-
## License :scroll:
249+
## License :scroll:<a id="license"></a>
226250

227251
[Apache 2.0](LICENSE)

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "delayed-async-tasks-manager",
3-
"version": "1.0.0",
4-
"description": "A scheduler for one-time (non-periodic) asynchronous tasks, designed to manage delayed executions. Features status getters to communicate the execution status, the ability to abort a pending execution, and the option to gracefully await the completion of all ongoing executions or a specific task.",
3+
"version": "1.0.1",
4+
"description": "A scheduler for one-time (non-periodic) asynchronous tasks, designed to manage delayed executions. It features status getters to communicate the execution state, a robust error handling mechanism for capturing uncaught errors, and the ability to abort pending executions. Additionally, it offers the option to gracefully await the completion of all ongoing tasks or a specific task.",
55
"repository": {
66
"type": "git",
77
"url": "git+https://github.com/ori88c/delayed-async-tasks-manager.git"

0 commit comments

Comments
 (0)