Skip to content

Commit

Permalink
Basic API doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Exelord committed Feb 2, 2023
1 parent 1420df4 commit a97b80f
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 2 deletions.
34 changes: 34 additions & 0 deletions docs/job.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Job

A job is a

## API

### Properties

- `value` - The result of a successful Task execution.
- `error` - The reason why a Task execution was unsuccessful.
- `status` - The current status of the Task. Can be: `idle`, `pending`, `fulfilled`, `rejected`, or `aborted`.
- `isIdle` - A boolean indicating whether the Task is idle.
- `isPending` - A boolean indicating whether the Task is pending.
- `isFulfilled` - A boolean indicating whether the Task was successful.
- `isRejected` - A boolean indicating whether the Task was unsuccessful.
- `isSettled` - A boolean indicating whether the Task has completed (fulfilled or rejected).
- `isAborted` - A boolean indicating whether the Task was cancelled.
- `signal` - An AbortSignal object for interpolation with signal-supported solution.

### Methods

- `perform()` - Starts execution of the Task.
- `abort(cancelReason)` - Aborts the Task with an optional cancel reason.
- `then(onFulfilled, onRejected)` - Registers callbacks to be called when the Task is fulfilled or rejected.
- `catch(onRejected)` - Registers a callback to be called when the Task is rejected.
- `finally(onFinally)` - Registers a callback to be called when the Task is settled.
- `addEventListener(type, listener, options)` - Registers an event listener for Task events.
- `removeEventListener(type, listener, options)` - Removes an event listener for Task events.

### Events

- `fulfill` - Triggered when the Task is fulfilled.
- `reject` - Triggered when the Task is rejected.
- `abort` - Triggered when the Task is cancelled.
45 changes: 45 additions & 0 deletions docs/task.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Task

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.

## API

### Construction

```ts
import { createTask } from 'solid-tasks';

const task = createTask(async (signal) => {
const response = await fetch('...', { signal })
return response.json();
});
```

### Properties

- `value` - The result of a successful Task execution.
- `error` - The reason why a Task execution was unsuccessful.
- `status` - The current status of the Task. Can be: `idle`, `pending`, `fulfilled`, `rejected`, or `aborted`.
- `isIdle` - A boolean indicating whether the Task is idle.
- `isPending` - A boolean indicating whether the Task is pending.
- `isFulfilled` - A boolean indicating whether the Task was successful.
- `isRejected` - A boolean indicating whether the Task was unsuccessful.
- `isSettled` - A boolean indicating whether the Task has completed (fulfilled or rejected).
- `isAborted` - A boolean indicating whether the Task was cancelled.
- `signal` - An AbortSignal object for interpolation with signal-supported solution.

### Methods

- `perform()` - Starts execution of the Task.
- `abort(cancelReason)` - Aborts the Task with an optional cancel reason.
- `then(onFulfilled, onRejected)` - Registers callbacks to be called when the Task is fulfilled or rejected.
- `catch(onRejected)` - Registers a callback to be called when the Task is rejected.
- `finally(onFinally)` - Registers a callback to be called when the Task is settled.
- `addEventListener(type, listener, options)` - Registers an event listener for Task events.
- `removeEventListener(type, listener, options)` - Removes an event listener for Task events.

### Events

- `fulfill` - Triggered when the Task is fulfilled.
- `reject` - Triggered when the Task is rejected.
- `abort` - Triggered when the Task is cancelled.
1 change: 0 additions & 1 deletion docs/usage.md

This file was deleted.

1 change: 0 additions & 1 deletion docs/why.md

This file was deleted.

0 comments on commit a97b80f

Please sign in to comment.