Skip to content

fix(timer): settle concurrent interval reads in order - #81

Open
rekcilyssup wants to merge 2 commits into
cordiverse:mainfrom
rekcilyssup:fix/interval-concurrent-reads
Open

fix(timer): settle concurrent interval reads in order#81
rekcilyssup wants to merge 2 commits into
cordiverse:mainfrom
rekcilyssup:fix/interval-concurrent-reads

Conversation

@rekcilyssup

Copy link
Copy Markdown

Closes #49

Problem

The async iterator returned by ctx.interval(delay) stored a single pending
resolver. Each next() overwrote it, so:

  • a timer tick could only settle the most recent read;
  • earlier concurrent reads stayed pending forever;
  • return(), throw(), and context disposal could only settle the latest read.

Fix

Replace the single resolver with a FIFO queue of pending reads:

  • each timer tick resolves the oldest pending read;
  • return() resolves every remaining read as done;
  • throw() rejects every remaining read with the supplied reason;
  • context disposal rejects every remaining read with the disposal error;
  • ticks received while no read is pending are still dropped (pulse behavior preserved).

Tests

Added 4 tests covering: ordered settlement of concurrent reads, return()
settling all pending reads, throw() rejecting all pending reads, and context
disposal rejecting all pending reads.

Verified locally: yarn lint, yarn build, yarn test (167 passed).

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.

Concurrent interval iterator reads can remain pending forever

1 participant