From 5bc568384eeb6ea09c14abc98f7788826ebc6afe Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Wed, 26 Jun 2024 13:22:36 +0900 Subject: [PATCH] docs: update --- docs/pages/coro-blocking-code.mdx | 4 ++++ docs/pages/coro-context-switches.mdx | 8 ++++++++ docs/pages/coro-io.mdx | 2 +- docs/pages/coro-scheduler.mdx | 10 ++++++++-- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/docs/pages/coro-blocking-code.mdx b/docs/pages/coro-blocking-code.mdx index e7ecb00..3f94b2e 100644 --- a/docs/pages/coro-blocking-code.mdx +++ b/docs/pages/coro-blocking-code.mdx @@ -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(); ``` diff --git a/docs/pages/coro-context-switches.mdx b/docs/pages/coro-context-switches.mdx index 4152be6..b95c45a 100644 --- a/docs/pages/coro-context-switches.mdx +++ b/docs/pages/coro-context-switches.mdx @@ -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. diff --git a/docs/pages/coro-io.mdx b/docs/pages/coro-io.mdx index 4358939..23cf623 100644 --- a/docs/pages/coro-io.mdx +++ b/docs/pages/coro-io.mdx @@ -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. diff --git a/docs/pages/coro-scheduler.mdx b/docs/pages/coro-scheduler.mdx index 736a8e1..5253fda 100644 --- a/docs/pages/coro-scheduler.mdx +++ b/docs/pages/coro-scheduler.mdx @@ -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