Skip to content

Commit a97b80f

Browse files
committed
Basic API doc
1 parent 1420df4 commit a97b80f

File tree

4 files changed

+79
-2
lines changed

4 files changed

+79
-2
lines changed

docs/job.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Job
2+
3+
A job is a
4+
5+
## API
6+
7+
### Properties
8+
9+
- `value` - The result of a successful Task execution.
10+
- `error` - The reason why a Task execution was unsuccessful.
11+
- `status` - The current status of the Task. Can be: `idle`, `pending`, `fulfilled`, `rejected`, or `aborted`.
12+
- `isIdle` - A boolean indicating whether the Task is idle.
13+
- `isPending` - A boolean indicating whether the Task is pending.
14+
- `isFulfilled` - A boolean indicating whether the Task was successful.
15+
- `isRejected` - A boolean indicating whether the Task was unsuccessful.
16+
- `isSettled` - A boolean indicating whether the Task has completed (fulfilled or rejected).
17+
- `isAborted` - A boolean indicating whether the Task was cancelled.
18+
- `signal` - An AbortSignal object for interpolation with signal-supported solution.
19+
20+
### Methods
21+
22+
- `perform()` - Starts execution of the Task.
23+
- `abort(cancelReason)` - Aborts the Task with an optional cancel reason.
24+
- `then(onFulfilled, onRejected)` - Registers callbacks to be called when the Task is fulfilled or rejected.
25+
- `catch(onRejected)` - Registers a callback to be called when the Task is rejected.
26+
- `finally(onFinally)` - Registers a callback to be called when the Task is settled.
27+
- `addEventListener(type, listener, options)` - Registers an event listener for Task events.
28+
- `removeEventListener(type, listener, options)` - Removes an event listener for Task events.
29+
30+
### Events
31+
32+
- `fulfill` - Triggered when the Task is fulfilled.
33+
- `reject` - Triggered when the Task is rejected.
34+
- `abort` - Triggered when the Task is cancelled.

docs/task.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Task
2+
3+
A Task represents an asynchronous computation. It is a wrapper around a Promise that provides additional functionality and events. It can be performed only once and it manages the state of the promise. The task has built-in cancellation mechanism.
4+
5+
## API
6+
7+
### Construction
8+
9+
```ts
10+
import { createTask } from 'solid-tasks';
11+
12+
const task = createTask(async (signal) => {
13+
const response = await fetch('...', { signal })
14+
return response.json();
15+
});
16+
```
17+
18+
### Properties
19+
20+
- `value` - The result of a successful Task execution.
21+
- `error` - The reason why a Task execution was unsuccessful.
22+
- `status` - The current status of the Task. Can be: `idle`, `pending`, `fulfilled`, `rejected`, or `aborted`.
23+
- `isIdle` - A boolean indicating whether the Task is idle.
24+
- `isPending` - A boolean indicating whether the Task is pending.
25+
- `isFulfilled` - A boolean indicating whether the Task was successful.
26+
- `isRejected` - A boolean indicating whether the Task was unsuccessful.
27+
- `isSettled` - A boolean indicating whether the Task has completed (fulfilled or rejected).
28+
- `isAborted` - A boolean indicating whether the Task was cancelled.
29+
- `signal` - An AbortSignal object for interpolation with signal-supported solution.
30+
31+
### Methods
32+
33+
- `perform()` - Starts execution of the Task.
34+
- `abort(cancelReason)` - Aborts the Task with an optional cancel reason.
35+
- `then(onFulfilled, onRejected)` - Registers callbacks to be called when the Task is fulfilled or rejected.
36+
- `catch(onRejected)` - Registers a callback to be called when the Task is rejected.
37+
- `finally(onFinally)` - Registers a callback to be called when the Task is settled.
38+
- `addEventListener(type, listener, options)` - Registers an event listener for Task events.
39+
- `removeEventListener(type, listener, options)` - Removes an event listener for Task events.
40+
41+
### Events
42+
43+
- `fulfill` - Triggered when the Task is fulfilled.
44+
- `reject` - Triggered when the Task is rejected.
45+
- `abort` - Triggered when the Task is cancelled.

docs/usage.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/why.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)