Skip to content

feat(await): add optional timeout and poll_completion to await_completion#62

Merged
HonestMajority merged 2 commits intomainfrom
task/impl-await-timeout-019cfc1d
Mar 17, 2026
Merged

feat(await): add optional timeout and poll_completion to await_completion#62
HonestMajority merged 2 commits intomainfrom
task/impl-await-timeout-019cfc1d

Conversation

@HonestMajority
Copy link
Copy Markdown
Contributor

@HonestMajority HonestMajority commented Mar 17, 2026

Summary

  • Add optional timeout: Option<Duration> parameter to await_completion — if the timeout expires before the job reaches a terminal state, returns JobError::TimedOut
  • Add non-blocking poll_completion convenience method — returns the terminal state immediately if done, or None if still running
  • Add JobError::TimedOut(JobId) error variant

Motivation

await_completion (added in #59) blocks indefinitely if a job never completes. Callers need a way to limit how long they wait. Additionally, some callers want a non-blocking check without subscribing to notifications.

Changes

await_completion timeout (src/lib.rs)

  • Signature: await_completion(&self, id: JobId, timeout: Option<Duration>)
  • None preserves existing behavior (wait indefinitely)
  • Some(duration) wraps the notification wait with tokio::time::timeout
  • On expiry, returns JobError::TimedOut(id)

poll_completion (src/lib.rs)

  • Signature: poll_completion(&self, id: JobId) -> Result<Option<JobTerminalState>, JobError>
  • Loads the job from DB and checks terminal_state()
  • Returns immediately — no channel subscription needed

Error type (src/error.rs)

  • Added TimedOut(JobId) variant to JobError

Tests (tests/job.rs)

  • Updated existing await_completion tests to pass None for backward compat
  • Added test_await_completion_timeout — verifies TimedOut error on expiry
  • Added test_poll_completion — verifies None for running jobs, Some(Completed) for finished jobs

Test plan

  • Existing await_completion tests pass with None
  • Timeout test with short duration on a far-future job
  • Poll returns None for in-progress, Some(Completed) for finished
  • CI checks pass

🤖 Generated with Claude Code

HonestMajority and others added 2 commits March 17, 2026 15:14
Add an optional `timeout: Option<Duration>` parameter to
`await_completion` so callers can limit how long they wait for a job to
reach a terminal state. When the timeout elapses, a new
`JobError::TimedOut` is returned. Passing `None` preserves the original
indefinite-wait behaviour.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@HonestMajority HonestMajority changed the title feat(await): add optional timeout to await_completion feat(await): add optional timeout and poll_completion to await_completion Mar 17, 2026
@HonestMajority HonestMajority marked this pull request as ready for review March 17, 2026 16:03
@HonestMajority HonestMajority merged commit c2d072e into main Mar 17, 2026
4 checks passed
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.

2 participants