Skip to content

feat: advance the clock by a timer's full duration when passed#77

Merged
johngeorgewright merged 1 commit into
masterfrom
feat/timer-duration
Jun 5, 2026
Merged

feat: advance the clock by a timer's full duration when passed#77
johngeorgewright merged 1 commit into
masterfrom
feat/timer-duration

Conversation

@johngeorgewright

Copy link
Copy Markdown
Collaborator

Follow-up to the virtual-clock work released in 5.0.0.

Why

Consuming a timeline on a virtual clock needs timers to spend their time as they're passed. Previously onPass advanced the clock by the token's character count (T40 → 3 frames), and the only way to realise the 40-frame duration was to await TimelineTimer.promise. On a virtual clock that deadlocks: the promise resolves when the clock advances, but nothing advances it while you're blocked awaiting it.

What

  • TimelineItemTimer.onPass() now advances the clock by the timer's full duration (T40 → 40 frames). A pull-based consumer drives timing just by iterating — it never awaits the timer promise.
  • Adds test/streamBridge.test.ts: an end-to-end proof that a timeline and a setInterval-based transformer (sampleTime) share one @sinonjs/fake-timers-backed Clockable and line up deterministically (1 @20, 1 @40, 2 @60), plus a negative test showing the timing barrier rejects a value that arrives too early.

Notes

This is the linchpin for porting @johngw/stream-test to the virtual clock. With it, the consumer fixes are small: fromTimeline drops await timer.promise (just moves on), and expectTimeline reads the shared clock through a no-op-advance view and yields with a microtask instead of a (fakeable) setTimeout.

Behavioural change to onPass timing; safe within the 5.x line as timers are meant to represent durations.

🤖 Generated with Claude Code

Passing a `Tn` now advances the virtual clock by `n` frames (its
duration) rather than the 1-frame-per-character default. This lets a
pull-based consumer drive timing just by iterating — it never has to
await `TimelineTimer.promise`, which on a virtual clock would deadlock
(nothing advances the clock while you're blocked awaiting it).

Add an end-to-end test proving a timeline and a `setInterval`-based
transformer (sampleTime) can share one fake-timers-backed clock and line
up deterministically, plus a negative case showing the timing barrier
catches a value that arrives too early.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@johngeorgewright johngeorgewright merged commit 66993cc into master Jun 5, 2026
2 checks passed
@johngeorgewright johngeorgewright deleted the feat/timer-duration branch June 5, 2026 10:46
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