Zig's New Async I/O (Text Version)

2025年10月29日

AI 摘要 AI 生成,可能有误

本文是 Zigtoberfest 2025 演示的文字版,介绍了 Zig 的新异步 I/O 原语,这些原语将通过 std.Io 接口在即将发布的 Zig 0.16.0 中落地。通过一系列循序渐进的代码示例,文章演示了如何设置 Io 实现(类似于内存分配器)、如何使用 async/await 表达异步以实现并发执行,以及如何安全地处理错误和资源管理。文中还介绍了取消机制,展示了 defer 和 cancel 如何与 try 和 await 结合使用,以防止资源泄漏并生成更优化的代码。

Zig's New Async I/O (Text Version)

In celebration of the std.Io introduction patchset landing today, here is the text version of a short, interactive demo I gave at Zigtoberfest 2025.

This is a preview of the new async I/O primitives that will be available in the upcoming Zig 0.16.0, to be released in about 3-4 months. There is a lot more to get into, but for now here is an introduction into some of the core synchronization API that will be available for all Zig code to use.

继续阅读全文

为了尊重作者,这里只展示开头几段。你可以去原文阅读,或者在 HorizonReader 里读:划线做笔记、让 AI 帮忙。

更多来自 Andrew Kelley

Don't Take the Black Pill (Text Adaptation)

AI 摘要The author warns against the 'black pill'—the nihilistic despair that emerged from incel forums and was fictionalized in Cory Doctorow's 'Radicalized'—drawing a parallel to software engineers who feel hopeless about management blocking them from building quality software. He describes coping strategies like 'Benevolent Noncompliance,' secrecy, inception, misdirection, and the 'duck' trick, while arguing that software quality historically depended on engineers' strong negotiating power in the job market. Ultimately, he calls for preserving agency, insisting that computers—like a 'user-agent' browser—should always serve the person directly interacting with them rather than hostile third-party interests.

My Thoughts on the Bun Rust Rewrite

AI 摘要The author, Zig's project lead, recounts the deteriorating relationship between the Zig community and Bun's founder Jarred, citing his VC-driven management failures, sloppy code quality, and diverging values, which made the Zig Software Foundation relieved when Anthropic acquired Bun and it was rewritten in Rust. He rebuts the rewrite announcement's blog post, arguing that bugs are eliminated through dedicated engineering effort rather than language features alone, and disputing its claims about testing, performance, and binary size. He concludes the conflict was never about Zig versus Rust but about clashing value systems, and reveals that Jarred engaged in cruel, illegal employment practices, regretting not severing ties sooner.

An Open Letter to Everyone I've Butted Heads With

AI 摘要Reflecting on Zig's 10th anniversary, the author examines his negative interactions with community members and concludes that such conflicts stem from programmers' lack of agency over the technologies they depend on, which naturally breeds frustration and anger. He apologizes for his own grumpy moments, emphasizes that he respects and cares even for his critics, and vows to bring more empathy to his daily interactions while continuing to grow Zig into a mainstream, welcoming project.

Renting is for Suckers

AI 摘要The article argues that cloud computing and cloud-based AI coding services are modern forms of 'renting' that violate basic financial principles, as owning hardware is orders of magnitude cheaper—citing the author's $3,000 Mac mini for Zig's CI versus $42,000/year for a cloud runner. It claims cloud and AI companies use marketing, conference sponsorships, and propaganda to convince developers to abandon ownership, transferring massive wealth to a few large corporations while introducing opaque costs and trust risks, such as the potential for LLM providers to manipulate agent behavior for profit. The author concludes by urging programmers to reject cloud and agentic coding services, which can cost hundreds to tens of thousands of dollars monthly, and instead use their own powerful, already-owned computers for free, private programming.

OpenZFS Bug Ported to Zig

AI 摘要The author ports a recent (almost) catastrophic OpenZFS bug from C to Zig to see whether Zig's tooling would have caught the error. After fixing a redeclaration of 'cols' flagged by zig fmt's --ast-check, the tool immediately reports the critical issue: the computed 'psize' is an unused local constant, exposing the original bug of returning 'asize' instead of the correct 'psize'. Notably, Zig caught the bug through these basic checks alone, without even invoking the type checker.