Hacker News new | ask | show | jobs
by ktpsns 36 days ago
Honest question, what is the zig version of goroutines these days? They removed async from the spec.

Honestly the only reason why I stick to golang for some projects are goroutines.

1 comments

Zig 0.16.0 was the big, recent async update. Go channels are handled as std.Io.Queue, the select keyword is handled with std.Io.Select, and goroutines are handled with std.Io.async and std.Io.concurrent. The difference between async and concurrent calls are essentially: async calls may be called concurrently, or they may not (the execution of the async function is not dependent on the caller continuing to execute - like reading a set of files), and concurrent must execute concurrently (the execution of the concurrent function depends on the caller continuing to execute - like a client+server interaction, and will crash if the environment cannot spawn concurrent processes).

The fully userspace implementation is a bit more syntactically clunky than the concurrency primitives in Go, but it is very similar semantically.

Thank you for this valuable comment!

I remember having read somewhere that zig now requires to pass the Io argument around, which one can interpret again as "colored functions". IMHO it is a missed opportunity not to implement a more polished syntax and make a message passing paradigm a "first class citizen" in zig. Anyway, I like the fact that zig is iteratively "improved" and not a virtually "dead" language compared to golang :-)