# How to run an async task as detached

**URL:** <https://ziggit.dev/t/how-to-run-an-async-task-as-detached/12814>\
**Category:** Help\
**Tags:** standard-library\
**Created:** [November 2, 2025, 11:45pm UTC](https://ziggit.dev/t/how-to-run-an-async-task-as-detached/12814 "2025-11-02T23:45:37Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![vulpesx](https://ziggit.dev/user_avatar/ziggit.dev/vulpesx/32/3989_2.png) [@vulpesx](https://ziggit.dev/u/vulpesx)\
**Post date:** [November 3, 2025, 11:39pm UTC](https://ziggit.dev/t/how-to-run-an-async-task-as-detached/12814/4 "2025-11-03T23:39:42Z")

</div>

> [@raugl](#):
>
> I assumed that `std.Io.Group` would eventually fill up with futures after a lot of connection, but thinking more about it, it’d make more sense for it to start executing them as soon as possible

Those details are up to the Io implementation, `Threaded` uses a linked list with heap allocated nodes.

> [@raugl](#):
>
> It works fine, but I don’t love all the `catch |err|`s

You can propagate the error through an out parameter, but it is just better practice to deal with them in `handleConnection`.

> [@raugl](#):
>
> Also I’m not sure that it’s impossible to leak a stream from `defer _ = accept.cancel(io) catch {}`

it is, `cancel` does return the result of the task if it finished before it could be cancelled, you have to deal with that `defer if(accept.cance(io)) |stream| stream.close() else |_| {};`  
I’m surprised that discarding hides the type mismatch of the success case being a stream and the error case being void (your `catch {}`). Though I can see how It’d make sense to do that, I dont think it should as it hides resource managment errors like this.

> [@raugl](#):
>
> operations on the reader and writer integrate implicitly into the event loop, though I would assume so

the interfaces have no knowledge of `Io`, and they shouldn’t, otherwise they wouldn’t be arbitrary streams of data.  
The implementation however should go through `Io`, which you can see as you have to give it `io` when you create them.

---

_[View the full topic](https://ziggit.dev/t/how-to-run-an-async-task-as-detached/12814)._
