# std.Io: fix and improve Group API · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/2adfd4d107f071f91608bef22c7e91b1a9a93470)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 2adfd4d107f071f91608bef22c7e91b1a9a93470

Requested commit: 2adfd4d107f071f91608bef22c7e91b1a9a93470

Commit: 2adfd4d107f071f91608bef22c7e91b1a9a93470

Tree: ef9da0bd175a2b4ddd12842e44df243606f353bf

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
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

```

## Parents

- [f862762f091637ad0d17c4735226c0c477c2cb3e](https://git.cafe/gitcafe/zig/commit/f862762f091637ad0d17c4735226c0c477c2cb3e?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/2adfd4d107f071f91608bef22c7e91b1a9a93470?format=markdown)
