mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-08 01:24:49 +01:00
std.Io: fix and improve Group API
Rename `wait` to `await` to be consistent with Future API. The convention here is that this set of functionality goes together: * async/concurrent * await/cancel Also rename Select `wait` to `await` for the same reason. `Group.await` now can return `error.Canceled`. Furthermore, `Group.await` does not auto-propagate cancelation. Instead, users should follow the pattern of `defer group.cancel(io);` after initialization, and doing `try group.await(io);` at the end of the success path. Advanced logic can choose to do something other than this pattern in the event of cancelation. Additionally, fixes a bug in `std.Io.Threaded` future await, in which it swallowed an `error.Canceled`. Now if a task is canceled while awaiting a future, after propagating the cancel request, it also recancels, meaning that the awaiting task will properly detect its own cancelation at the next cancelation point. Furthermore, fixes a bug in the compiler where `error.Canceled` was being swallowed in `dispatchPrelinkWork`. Finally, fixes std.crypto code that inappropriately used `catch unreachable` in response to cancelation without even so much as a comment explaining why it was believed to be unreachable. Now, those functions have `error.Canceled` in the error set and propagate cancelation properly. With this way of doing things, `Group.await` has a nice property: even if all tasks in the group are CPU bound and without cancelation points, the `Group.await` can still be canceled. In such case, the task that was waiting for `await` wakes up with a chance to do some more resource cleanup tasks, such as canceling more things, before entering the deferred `Group.cancel` call at which point it has to suspend until the canceled but uninterruptible CPU bound tasks complete. closes #30601
This commit is contained in:
parent
f862762f09
commit
2adfd4d107
16 changed files with 108 additions and 78 deletions
|
|
@ -1951,7 +1951,7 @@ pub fn main() anyerror!void {
|
|||
} });
|
||||
}
|
||||
|
||||
group.wait(io);
|
||||
try group.await(io);
|
||||
}
|
||||
|
||||
const Job = struct {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue