Skip to content

Adds async versions of ReadModelBase.Start()#191

Merged
condron merged 2 commits into
masterfrom
joshkempner/block-until-live
Mar 24, 2026
Merged

Adds async versions of ReadModelBase.Start()#191
condron merged 2 commits into
masterfrom
joshkempner/block-until-live

Conversation

@joshkempner
Copy link
Copy Markdown
Contributor

What does this pull request do?
Enables a mechanism to determine when a read model is live using async-await instead of using blockUntilLive in calls to Start.

How does this pull request accomplish that goal?
Adds a StartAsync method for each overload of Start in ReadModelBase. These methods perform event playback on a task pool thread. The class exposes an awaitable IsLive property that completes when all async playback Tasks have completed.

Why is this pull request important?
The use of blockUntilLive can cause problems when running unit tests in the lightweight VMs that are often used for CI builds. The problem is that Start<T>(blockUntilLive: true) synchronously blocks a taskpool thread while waiting for the stream reader to catch up. On a runner with a small number of cores, even sequential tests within one assembly can starve the pool if multiple ReadModelBase instances are constructed in quick succession since each test class creates fresh RMs in its constructor.

Link to any issues that this resolves
This does not address any open issues.

Checklist

  • All unit tests in the solution must pass on all versions of .NET that the solution supports
  • Any new code must be covered by at least one unit test
  • All public methods must be documented with XML comments

@joshkempner joshkempner requested a review from condron March 24, 2026 16:27
@joshkempner joshkempner self-assigned this Mar 24, 2026
@joshkempner joshkempner requested a review from a team as a code owner March 24, 2026 16:27
@joshkempner joshkempner force-pushed the joshkempner/block-until-live branch from b13ecfc to da59976 Compare March 24, 2026 16:59
Adds a `StartAsync` method for each overload of `Start` in `ReadModelBase`. These methods perform event playback on a task pool thread. The class exposes an awaitable `IsLive` property that completes when all async playback Tasks have completed.
@joshkempner joshkempner force-pushed the joshkempner/block-until-live branch from da59976 to 761d21b Compare March 24, 2026 17:05
@condron condron merged commit 51b4ac4 into master Mar 24, 2026
4 checks passed
@condron condron deleted the joshkempner/block-until-live branch March 24, 2026 19:04
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.

2 participants