Skip to content

feat(appkit-ui): internal usePoll scheduler hook (poll 2/4) - #585

Draft
atilafassina wants to merge 1 commit into
poll-1-refetchfrom
poll-2-usepoll
Draft

atilafassina wants to merge 1 commit into
poll-1-refetchfrom
poll-2-usepoll

Conversation

@atilafassina

Copy link
Copy Markdown
Contributor

Stacked PR 2 of 4 — analytics query polling.
Base: poll-1-refetch (PR 1). Merge after PR 1.

What

Add usePoll(runOnce, options) — a transport-agnostic polling scheduler hook. Knows nothing about analytics/SSE/cursors.

  • Immediate-first tick + interval cadence; in-flight skip guard; exponential backoff (1→2→4→8s capped, ticking-but-skipping until deadline); optional maxConsecutiveErrors pause.
  • Controls: pause/resume/restart/refetch. Telemetry: attempts, errors, skipped, consecutiveErrors, lastLatencyMs, latency:{p50,p95}.

Dormant

Internal only — not exported from any barrel; option/result types kept file-local so it lands without tripping knip.

Stack

  1. internal refetch + uncached mode
  2. ← this PR internal usePoll scheduler
  3. useAnalyticsQuery({ poll }) binding + public types
  4. docs

Tests

13 Vitest fake-timer tests (via vi.advanceTimersByTimeAsync inside async act()); full suite green.

This pull request and its description were written by Isaac.

Transport-agnostic polling scheduler: usePoll(runOnce, options) drives an
async run-once action and reports lifecycle + telemetry (attempts, errors,
skipped, consecutiveErrors, lastLatencyMs, latency:{p50,p95}) with controls
(pause/resume/restart/refetch). Owns immediate-first tick, interval cadence,
in-flight skip guard, exponential backoff (1→2→4→8s capped, ticking-but-
skipping until deadline), and optional maxConsecutiveErrors pause. Knows
nothing of analytics/SSE/cursors. Internal — not exported from any barrel;
option/result types kept file-local so it lands dormant without tripping
knip. Wired behind useAnalyticsQuery({ poll }) in phase 3.

Tested with Vitest fake timers via vi.advanceTimersByTimeAsync inside
async act() (no waitFor under fake timers).

xavier loop: iteration 3 (phase 2/4)

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Atila Fassina <atila@fassina.eu>
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