Skip to content

Make sleep() propagate error.Canceled - #53

Merged
lalinsky merged 1 commit into
mainfrom
cancelable-sleep
Oct 18, 2025
Merged

lalinsky merged 1 commit into
mainfrom
cancelable-sleep

Conversation

@lalinsky

@lalinsky lalinsky commented Oct 18, 2025 •

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Sleep operations are now cancelable, providing greater control over task lifecycle and enabling interruption of long-running operations within concurrent contexts.
  • Improvements

    • Enhanced error propagation in sleep operations throughout async execution paths, ensuring consistent and predictable error handling behavior in runtime environments.

@lalinsky
lalinsky merged commit 71fcb33 into main Oct 18, 2025
@lalinsky
lalinsky deleted the cancelable-sleep branch October 18, 2025 17:43
@coderabbitai

coderabbitai Bot commented Oct 18, 2025 •

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

Walkthrough

This PR introduces cancellation support to sleep operations by changing Executor.sleep and Runtime.sleep return types from void to Cancelable!void, enabling error propagation for cancellation and timeout scenarios. All call sites and related function signatures across examples and internal code are updated to handle the new error-returning sleep semantics.

Changes

Cohort / File(s) Summary
Runtime Core Changes
src/runtime.zig, src/zio.zig
Executor.sleep and Runtime.sleep signatures updated from void to Cancelable!void to support cancellation; Cancelable type publicly exported
Example Function Signatures
examples/producer_consumer.zig, examples/sleep.zig
Worker function signatures updated to return Cancelable!void; JoinHandle type parameters updated from void to Cancelable!void
Sleep Call Updates
examples/producer_consumer.zig, examples/sleep.zig, examples/udp_echo.zig, src/udp.zig
Sleep calls prefixed with try to propagate errors (e.g., rt.sleep(ms) → try rt.sleep(ms))

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 Hop, hop, hop—now sleep can cancel!
No more blocked by slumber's wall;
Errors flow where silence fell,
Woken by a gentle bell. ✨

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cancelable-sleep

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6c76bd4 and 6e89376.

📒 Files selected for processing (6)
  • examples/producer_consumer.zig (4 hunks)
  • examples/sleep.zig (1 hunks)
  • examples/udp_echo.zig (1 hunks)
  • src/runtime.zig (12 hunks)
  • src/udp.zig (1 hunks)
  • src/zio.zig (1 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

lalinsky added a commit that referenced this pull request Nov 18, 2025
106f1eb Add getaddrinfo and getnameinfo wrappers (#53)

git-subtree-dir: src/lib/aio
git-subtree-split: 106f1eb
lalinsky added a commit that referenced this pull request Jan 6, 2026
* Add getaddrinfo and getnameinfo wrappers

Add cross-platform wrappers for getaddrinfo/getnameinfo to prepare for
Zig 0.16 migration where std.posix is being removed.

- Add getaddrinfo() wrapper with support for both Windows and POSIX
- Add getnameinfo() wrapper with NI packed struct for flags
- Define Windows extern functions and addrinfo struct (removed from ws2_32)
- Add comprehensive error conversion for both platforms
- Handle EAI.SYSTEM by reading actual errno value
- Add tests for resolving example.com and reverse lookup of 127.0.0.1

* Fix NI type compatibility across platforms

Copy NI definitions from Zig 0.16 std.c to ensure compatibility across
all platforms (Linux, BSD variants, Illumos, Serenity, etc.).

Previously, std.c.NI was void for FreeBSD and other platforms not
explicitly supported in Zig 0.15.2, causing compilation errors.

This adds explicit packed struct definitions for all platforms based
on their platform-specific getnameinfo flags.

* Add custom getnameinfo extern for BSD platforms

On BSD platforms (FreeBSD, NetBSD, OpenBSD, etc.), std.c.NI is void in
Zig 0.15.2, which causes std.c.getnameinfo to have an invalid signature
(void parameters not allowed).

This adds a custom extern declaration that takes c_int for flags instead
of the problematic NI type, and uses it for platforms where std.c.NI is
not properly defined.

Split getnameinfo implementation:
- Use std.c.getnameinfo for Linux, Emscripten, Illumos, Serenity
- Use posix_extern.getnameinfo for BSD and other platforms

* Remove getnameinfo wrapper

Remove getnameinfo wrapper due to cross-platform NI type compatibility
issues on macOS/BSD. The getaddrinfo wrapper remains functional and is
sufficient for the Zig 0.16 migration.

Removed:
- NI type definitions for all platforms
- getnameinfo() function
- GetNameInfoError error set
- errnoToGetNameInfoError() function
- posix_extern struct
- windows_NI type
- getnameinfo test

* Fix Windows calling convention to lowercase

Change callconv(std.os.windows.WINAPI) to callconv(.winapi) in Windows
extern function declarations. The calling convention should use the
lowercase .winapi syntax.
@coderabbitai coderabbitai Bot mentioned this pull request Jan 14, 2026
2 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant