Skip to content

Commit

Permalink
docs: update
Browse files Browse the repository at this point in the history
  • Loading branch information
Cloudef committed Jun 26, 2024
1 parent 79c8d03 commit 5bc5683
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
4 changes: 4 additions & 0 deletions docs/pages/coro-blocking-code.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ try pool.start(std.testing.allocator, 0);
defer pool.deinit(); // pool must always be destroyed before scheduler
_ = try scheduler.spawn(task, .{&pool}, .{});
// Or alternatively, which does the same as above
_ = try pool.spawnForCompletition(&scheduler, blockingCode, .{}, .{});
try scheduler.run();
```

8 changes: 8 additions & 0 deletions docs/pages/coro-context-switches.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,11 @@ switch (task.state(SomeEnum)) {
value => task.wakeup(),
}
```

Shorthand for waking up task when the state is as expected.

```zig
task.wakeupIf(Task.SomeEnum);
```

Trying to wakeup a task that was not yielded by the user code is an programming error.
2 changes: 1 addition & 1 deletion docs/pages/coro-io.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ outside a task then the call would be equal to calling the equal function from t
Use `aio.Cancel` operation to cancel the currently running operations in a task.
The `out_error` of such operation will then be set as `error.Canceled`.

Alternatively it's possible to call `task.complete(.cancel);` to actively cancel a task and collect its partial result.
Alternatively it's possible to call `task.cancel()`, or `task.complete(.cancel);` to actively cancel a task and collect its partial result.
10 changes: 8 additions & 2 deletions docs/pages/coro-scheduler.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,25 @@ yields or performs a IO operation using one of the `coro.io` namespace functions
var task = try scheduler.spawn(entrypoint, .{ 1, "args" }, .{});
```

In case the return type of the function can not be deduced by the compiler, use the spawnAny variant.

```zig
var task = try scheduler.spawnAny(void, entrypoint, .{ 1, "args" }, .{});
```

### Collecting result from a task

Use the following to collect a result of a task.
After collecting the result, the task handle is no longer valid.

```zig
const res = task.collect(.wait);
const res = task.complete(.wait);
```

To cancel and collect partial result.

```zig
const res = task.collect(.cancel);
const res = task.complete(.cancel);
```

### Running
Expand Down

0 comments on commit 5bc5683

Please sign in to comment.