Skip to content

feat(poll): add generic async poll function#7

Open
polubis wants to merge 3 commits into
mainfrom
claude/generic-poll-function-c3rbqn
Open

feat(poll): add generic async poll function#7
polubis wants to merge 3 commits into
mainfrom
claude/generic-poll-function-c3rbqn

Conversation

@polubis

@polubis polubis commented Jul 12, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds a new @repo/poll package with a generic poll(fn, options) async helper.
  • Options: maxAttempts (caps retries, throws PollMaxAttemptsError when exhausted), delayMs (fixed number or (attempt: number) => number), until (predicate over the latest result; resolves once true), and stopEmitter (receives a stop callback — calling it cuts a pending delay short, runs one final attempt, and resolves with that result regardless of until).

Test plan

  • pnpm --filter @repo/poll test — 5 unit tests covering early resolution via until, per-attempt delayMs, PollMaxAttemptsError on exhaustion, and both stopEmitter behaviors (stop before first attempt, stop cutting a pending delay short).
  • pnpm --filter @repo/poll lint
  • pnpm --filter @repo/poll check-types
  • pnpm --filter @repo/poll build
  • Full ci:verify suite ran via the repo's pre-push hook (format, lint, check-types, test, build across all workspaces) — 40/40 tasks passed.

Generated by Claude Code

claude added 3 commits July 12, 2026 16:26
New @repo/poll package with a poll(fn, options) helper supporting
maxAttempts, a fixed or attempt-aware delayMs, an until predicate to
resolve early, and an optional stopEmitter to cancel a pending delay,
run one final attempt, then stop.
Adds coverage for zero/one-attempt boundaries, async fn and
non-primitive results, actual delay timing via fake timers, error
propagation from fn/until, repeated/late stop() calls, and
independent concurrent poll() calls not interfering with each other.
Adds an optional onTick(result, attempt) option, invoked after every
attempt (including the one that satisfies until, is cut short by
stopEmitter, or exhausts maxAttempts) so callers can observe progress
without changing the poll's own control flow.
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