feat(poll): add generic async poll function#7
Open
polubis wants to merge 3 commits into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
@repo/pollpackage with a genericpoll(fn, options)async helper.maxAttempts(caps retries, throwsPollMaxAttemptsErrorwhen exhausted),delayMs(fixed number or(attempt: number) => number),until(predicate over the latest result; resolves once true), andstopEmitter(receives astopcallback — calling it cuts a pending delay short, runs one final attempt, and resolves with that result regardless ofuntil).Test plan
pnpm --filter @repo/poll test— 5 unit tests covering early resolution viauntil, per-attemptdelayMs,PollMaxAttemptsErroron exhaustion, and bothstopEmitterbehaviors (stop before first attempt, stop cutting a pending delay short).pnpm --filter @repo/poll lintpnpm --filter @repo/poll check-typespnpm --filter @repo/poll buildci:verifysuite 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