feat: adds deadline/timeout support to IrrevocableContext - #82
Conversation
…rrevocableContext Additive integration of the deadline-related features from sanaz/context-with-tokio (ThrowableContext) onto main's IrrevocableContext: with_timeout/deadline/is_deadline_exceeded, deadline arm in run(), err(), and with_cancel(). The Go-style value bag from that branch was intentionally excluded (no consumer; deliberately dropped by PR #65's simplification). Candidate for evaluation; deadline is not yet wired into any consumer. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Claude (@claude) review this PR |
|
Claude finished S T (@staheri14)'s task —— View job PR Review: Add deadline/timeout support to
|
…l bound; add tests Addresses PR #82 review points 1, 7, 6, 4: - run() now short-circuits via err() before the select!, so an already-cancelled or already-expired context can't return Ok by racing an immediately-ready future (1) - test_run_short_circuits_when_deadline_already_passed covers that case (7) - test_run_cancellation_beats_deadline exercises the Some(deadline) arm's cancelled() branch via concurrent cancellation (6) - with_cancel returns impl Fn() + Send + Sync + Clone so the trigger can cross threads/tasks and be stored (4) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Thanks for the review Claude (@claude) — went through all points. Summary of what was addressed vs. deferred: Addressed in
Verification: context module 12/12, full suite 69 pass, Deferred to #83 (non-blocking):
|
There was a problem hiding this comment.
One small thing worth flagging before run() becomes the path everything funnels through. The span guard is held across the .await inside the select!, which makes the returned future !Send and can leak the span onto other tasks while the operation is suspended. It's pre-existing, but since run() is now the deadline aware entry point, better to move to .instrument() here before we wire search_by_id onto it. Not blocking, approving.
Thanks, addressed 2748462 |
Summary
Extends
IrrevocableContextwith deadline/timeout support and a couple of small conveniences, ported from the oldersanaz/context-with-tokiobranch (ThrowableContext) and adapted to main's current API and conventions.These features had never landed in
main: PR #65 introduced a deliberately simplified context (cancellation + irrecoverable-error propagation only). This PR adds back the deadline capability as a purely additive change — a context created withnewbehaves exactly as before.What's added
with_timeout(span, tag, dur)— root context that expires afterdurdeadline()/is_deadline_exceeded()— inspect the deadlinerun()now races the operation against the deadline and cancellation (whichever fires first)err()—Some(..)if the context is cancelled or past its deadlinewith_cancel(tag)— returns a child context plus a closure that cancels itChild contexts inherit the parent's deadline.
Deliberately excluded
The Go-style value bag (
with_value/value::<T>) from the source branch was left out — no consumer in the codebase, and it was intentionally dropped by #65's simplification.Not yet wired
This is a library-level addition.
BaseNode::search_by_idstill blocks onrx.recv()without a deadline; wiring it to run underctx.run(..)is a suggested follow-up.Testing
cargo test— full suite passes (context module 10/10, incl. 3 new tests for deadline/err/with_cancel)cargo clippy --all-targets --all-features -- -D warnings -D deprecated— clean🤖 Generated with Claude Code