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
+27-14Lines changed: 27 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -7,22 +7,35 @@ Key features include:
7
7
*__Status Communication__: Easily check the current status of the scheduled task.
8
8
*__Graceful Termination__: Await the completion of an ongoing execution, ensuring deterministic termination when needed.
9
9
10
-
This class is ideal for scenarios where precise control over the execution and termination of asynchronous tasks is required.
10
+
This class is ideal for scenarios where precise control over the execution and termination of asynchronous tasks is required. If you need to manage **multiple** asynchronous tasks, potentially in large numbers, consider the [delayed-async-tasks-manager](https://www.npmjs.com/package/delayed-async-tasks-manager) package, which extends the functionality of this package.
11
11
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
+
*[Graceful and Deterministic Termination](#graceful-termination)
18
+
*[Zero Over-Engineering, No External Dependencies](#no-external-dependencies)
19
+
*[Non-Persistent Scheduling](#non-persistent)
20
+
*[Error Handling](#error-handling)
21
+
*[Use-case Example](#use-case-example)
22
+
*[Breaking Change in Version 2.0.0](#breaking-change-2)
23
+
*[License](#license)
24
+
25
+
## Key Features :sparkles:<aid="key-features"></a>
13
26
14
27
*__Modern Substitute for Javascript's 'setTimeout'__: Specifically designed for scheduling asynchronous tasks.
15
-
*__Execution Status Getters__: Allows users to check the task's execution status, helping to prevent potential race conditions.
16
-
*__Graceful and Deterministic Termination__: The `awaitCompletionIfCurrentlyExecuting` method resolves once the currently executing task finishes, or resolves immediately if the task is not executing.
17
-
*__Robust Error Handling__: If the task throws an uncaught error, the error is captured and accessible via the `uncaughtRejection` getter.
28
+
*__Execution Status Getters :bar_chart:__: Allows users to check the task's execution status, helping to prevent potential race conditions.
29
+
*__Graceful and Deterministic Termination :hourglass:__: The `awaitCompletionIfCurrentlyExecuting` method resolves once the currently executing task finishes, or resolves immediately if the task is not executing.
30
+
*__Robust Error Handling :warning:__: If the task throws an uncaught error, the error is captured and accessible via the `uncaughtRejection` getter.
18
31
*__Comprehensive Documentation :books:__: The class is thoroughly documented, enabling IDEs to provide helpful tooltips that enhance the coding experience.
19
32
*__Fully Tested :test_tube:__: Extensively covered by unit tests.
20
33
*__No External Runtime Dependencies__: Lightweight component, only development dependencies are used.
21
34
* Non-Durable Scheduling: Scheduling stops if the application crashes or goes down.
22
35
* ES2020 Compatibility.
23
36
* TypeScript support.
24
37
25
-
## API
38
+
## API:globe_with_meridians:<aid="api"></a>
26
39
27
40
The `DelayedAsyncTask` class provides the following methods:
28
41
@@ -31,7 +44,7 @@ The `DelayedAsyncTask` class provides the following methods:
31
44
32
45
If needed, refer to the code documentation for a more comprehensive description of each method.
33
46
34
-
## Execution Status Getters :rocket:
47
+
## Execution Status Getters :mag:<aid="execution-status-getters"></a>
35
48
36
49
The `DelayedAsyncTask` class provides five getter methods to communicate the task's status to users:
37
50
@@ -41,7 +54,7 @@ The `DelayedAsyncTask` class provides five getter methods to communicate the tas
41
54
*`isCompleted`: Indicates that the task has completed.
42
55
*`isUncaughtRejectionOccurred`: Indicates that the task threw an uncaught error. The error can be accessed using the `uncaughtRejection` getter.
43
56
44
-
## Graceful and Deterministic Termination :hourglass:
57
+
## Graceful and Deterministic Termination :hourglass:<aid="graceful-termination"></a>
45
58
46
59
In the context of asynchronous tasks and schedulers, graceful and deterministic termination is **often overlooked**. `DelayedAsyncTask` provides an out-of-the-box mechanism to await the completion of an asynchronous task that has already started but not yet finished, via the `awaitCompletionIfCurrentlyExecuting` method.
47
60
@@ -100,17 +113,17 @@ class Component {
100
113
101
114
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, you may not be able to abort it. In such cases, you can ignore the reschedule request, await the current execution to complete, or implement any other business logic that suits your requirements.
102
115
103
-
## Zero Over-Engineering, No External Dependencies
116
+
## Zero Over-Engineering, No External Dependencies<aid="no-external-dependencies"></a>
104
117
105
118
This component provides a lightweight, dependency-free solution. It is designed to be simple and efficient, ensuring minimal overhead. Additionally, it can serve as a building block for more advanced implementations, such as a Delayed Async Tasks Manager, if needed.
This component features non-durable scheduling, which means that if the app crashes or goes down, scheduling stops.
110
123
111
124
If you need to guarantee durability over a multi-node deployment, consider using this scheduler as a building block or use other custom-made solutions for that purpose.
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:
116
129
@@ -119,7 +132,7 @@ Unlike `setTimeout` in Node.js, where errors from rejected promises propagate to
119
132
120
133
Ideally, a delayed task should handle its own errors and **avoid** throwing uncaught exceptions.
121
134
122
-
## Use-case Example :man_technologist:
135
+
## Use-case Example :man_technologist:<aid="use-case-example"></a>
123
136
124
137
Consider a Background Updates Manager. For simplicity, we assume that updates occur only following an on-demand request by the admin, triggered by the execution of the `scheduleNextJob` method. Additionally, assume that only one future background update task can be scheduled at any given time. This means that scheduling a new task will abort any previously scheduled task that has not yet started.
125
138
@@ -180,10 +193,10 @@ class BackgroundUpdatesManager {
180
193
}
181
194
```
182
195
183
-
## Breaking Change in Version 2.0.0
196
+
## Breaking Change in Version 2.0.0:boom:<aid="breaking-change-2"></a>
184
197
185
198
In version 2.0.0, the target compatibility has been upgraded from ES6 to ES2020. This change was made to leverage the widespread adoption of ES2020, in particular its native support for async/await.
Copy file name to clipboardExpand all lines: package.json
+7-1Lines changed: 7 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
{
2
2
"name": "delayed-async-task",
3
-
"version": "2.0.1",
3
+
"version": "2.0.2",
4
4
"description": "A modern `setTimeout` substitute tailored for asynchronous tasks, designed to schedule a single delayed execution. Features status getters to communicate the execution status, the ability to abort a pending execution, and the option to gracefully await the completion of an ongoing execution.",
0 commit comments