Skip to content

refactor: use node's timers/promises API for sleeps - #316

Open
mrafnadeem-apimatic wants to merge 3 commits into
devfrom
refactor/sleep
Open

refactor: use node's timers/promises API for sleeps#316
mrafnadeem-apimatic wants to merge 3 commits into
devfrom
refactor/sleep

Conversation

@mrafnadeem-apimatic

Copy link
Copy Markdown
Contributor

What

Replaces hand-rolled new Promise((resolve) => setTimeout(resolve, ms)) waits with the sleep helper backed by node:timers/promises.

  • Adds src/infrastructure/timer-extensions.tssleep(ms, signal?) returning 'ok' | 'cancelled' | 'failed', with the AbortSignal optional so uncancellable waits can use it too.
  • Interactive sdk publish polling now aborts its wait immediately on cancel instead of up to 10 s later.
  • Reuses the helper at the three remaining raw-setTimeout waits:
    • LoginAction.pollDeviceToken — device-login token poll
    • FileService.pollDeleteDirectory — delete retry backoff
    • pollUntilCompleted in portal-service — generation status poll

What is left alone

debounce-service.ts and hooks/utils.ts keep callback-style setTimeout: those are cancellable timers racing other work (a debounce window, a readline prompt timeout), not sleeps.

Testing

  • pnpm build — clean
  • pnpm lint — clean
  • pnpm test — 71 passing, 11 pending

Note: the posttest hook (eslint . --ext .ts) reports errors from untracked local .claude/worktrees/** copies. Pre-existing and unrelated to this change; src/ and test/ both lint clean.

🤖 Generated with Claude Code

mrafnadeem-apimatic and others added 3 commits August 11, 2026 15:21
Make the AbortSignal optional so the three uncancellable polling waits
(device-login token poll, delete-directory retry, generation status poll)
can share the same helper instead of hand-rolling a Promise wrapper.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

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