Is it possible for Zig's Io interface to queue up work that doesn't need to be awaited/canceled?

This is what Io.Group is for. If you want it to be detached, then use a process-wide Group that you initialize in main. You probably want to wait for it to finish before exiting the program, right?

// near the beginning of main after you init your Io
var group: Io.Group = .init;
defer group.cancel(io);

// your application code

This makes it so that you application finishes, you send a cancel request to your detached stuff (and then still wait for them to complete).

If you don’t want to wait for tasks in the group to complete you can call std.process.exit.

If you don’t want to send the cancel request, call try group.wait(io) after your application code. This way the cancel request happens only when an error occurs.

6 Likes