Do I need to defer cancel an std.Io.Group?

I’m working my way through ziglings and found it mysterious why it doesn’t defer cancel std.Io.Groups:

pub fn main(init: std.process.Init) !void {
    const io = init.io;

    var group: std.Io.Group = .init;
    // I would expect
    //   defer _ = group.cancel(io);
    // here.

    // Spawn 3 tasks in any order. Each sleeps for (id * 1) seconds
    // before printing, so the output order is deterministic.
    group.async(io, doWork, .{ io, 1 });
    group.async(io, doWork, .{ io, 3 });
    group.async(io, doWork, .{ io, 2 });
    ...
}

Am I missing something here?

Do I need to defer cancel an std.Io.Group?

Yes

Am I missing something here?

No. Well, only the fact that it returns void so you don’t need to discard the return value :slightly_smiling_face:

4 Likes