- Version
- 1.0.0
- License
- MIT
- Source
- AsyncTask.js, line 9
Constructor
new AsyncTask()
Creates a new AsyncTask instance. The task will be in 'pending' state until resolved, rejected, or cancelled.
Members
private #abortController :AbortController
Internal AbortController instance used for cancellation.
- Type
- AbortController
- Source
- AsyncTask.js, line 16
private #signal :AbortSignal
Abort signal to be passed to consumers (e.g. Fetch, plugin tasks, etc).
- Type
- AbortSignal
- Source
- AsyncTask.js, line 23
private #resolve :function
Promise resolve function (internal use).
- Type
- function
- Source
- AsyncTask.js, line 30
private #reject :function
Promise reject function (internal use).
- Type
- function
- Source
- AsyncTask.js, line 37
private #status :string
Current status of the task: 'pending', 'resolved', 'rejected', or 'cancelled'.
- Type
- string
- Source
- AsyncTask.js, line 44
promise :Promise<*>
The underlying promise that will resolve, reject, or cancel according to the task's outcome.
- Type
- Promise<*>
- Source
- AsyncTask.js, line 50
signal
Returns the AbortSignal associated with this task. Useful for passing to APIs that support cancellation.
- Returns
-
The signal instance.
- Type AbortSignal
- Source
- AsyncTask.js, line 115
status
Returns the current status of the task: 'pending', 'resolved', 'rejected', or 'cancelled'.
- Returns
-
The current status.
- Type string
- Source
- AsyncTask.js, line 121
Methods
resolve(value)
Resolves the task successfully. Sets status to 'resolved' and fulfills the promise.
| Name | Type | Description |
|---|---|---|
value |
* |
Value with which the promise will resolve. |
- Source
- AsyncTask.js, line 92
reject(reason)
Rejects the task with an error. Sets status to 'rejected' (or 'cancelled' if AbortError) and rejects the promise.
| Name | Type | Description |
|---|---|---|
reason |
* |
Reason for rejection (error object or value). |
- Source
- AsyncTask.js, line 98
cancel() → Promise
Cancels the task using the AbortController. Sets status to 'cancelled' and rejects the promise with an AbortError.
- Returns
-
Returns current promise.
- Type Promise
- Source
- AsyncTask.js, line 104