x.async: add structured concurrency helpers#27029
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a664ec8dd8
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if err.msg() == context_deadline_exceeded { | ||
| return error(err_timeout) |
There was a problem hiding this comment.
Preserve parent deadline cancellation error
When with_timeout_context exits via done_ch, it unconditionally remaps context deadline exceeded to async: timeout. That also catches the case where the parent context deadline fires first, so callers cannot distinguish an upstream deadline from this helper's own timeout. This contradicts the documented behavior that parent cancellation errors are returned as-is and can break retry/telemetry logic that treats upstream deadline expiry differently.
Useful? React with 👍 / 👎.
|
Ready for review / integration. Codex p2 fixed. |
This PR introduces
x.async, a small structured concurrency helper module built only on existing V primitives.I originally wrote this kind of tooling for my larger V projects, where I needed a simple and explicit way to coordinate tasks, cancellation, timeouts, worker limits, and error propagation. The module now feels mature enough to share as an experimental
x.module, while keeping the design intentionally modest and easy to review.What it provides:
Groupfor running related jobs with first-error propagation and cooperative cancellation.Task[T]for one value-returning background computation with explicitwait().Poolfor bounded concurrent work with non-blockingtry_submit()backpressure.every()for blocking periodic work controlled by context cancellation.with_timeout()helpers for bounding cooperative jobs.What it deliberately does not provide:
The current API is deliberately conservative:
Task.wait()is one-shot;Groupkeeps first-error behavior simple;Pool.try_submit()is explicit and non-blocking;The implementation is only a documented layer over existing V tools like
spawn,sync.WaitGroup,sync.Mutex, channels,context, andtime.I also added examples and integration-style tests for selected V modules such as
net.http,net.websocket,veb, andmcp, while keeping them local and synthetic so they do not depend on external services, ports, or fragile server shutdown behavior.Future additions could be discussed separately if maintainers think the direction is useful, for example:
x.async, if maintainers decide that would be valuable.The goal is not to replace V’s concurrency model, but to provide a small, predictable, well-tested helper layer for common coordination patterns.