Repository navigation
Avoid blocking WithLatestFrom value updates - #2630
Merged
glopesdev merged 1 commit intoJul 6, 2026
Merged
Conversation
Reimplement WithLatestFrom on a two-lock strategy, one gate serializing downstream delivery and a separate lock guarding only the cached latest value, so updates from the value sequence no longer wait on downstream processing of a source element. A slow downstream observer now delays only further source elements, not refreshes of the latest value, for example when software-timestamping a data sequence against a high-rate clock. Observable behavior is otherwise unchanged; the two-lock logic follows the current dotnet/reactive WithLatestFrom. Closes bonsai-rx#2600
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WithLatestFrompairs each source element with the latest value from a second sequence. It was initially built on top ofCombineLatest, which serializes both sequences and downstream delivery behind a single lock. With that one lock held for the duration of the downstreamOnNext, an incoming element on the value sequence could not refresh the cached latest value until the call returned, so a slow downstream observer would stall the value sequence for as long as it ran. This is common when software-timestamping a data sequence against a high-rate clock, where a slow consumer of the timestamped element stalls the shared clock sequence, blocking its producer so the device input buffer can overflow.This change reimplements the operator on the two-lock strategy from the current
WithLatestFromin dotnet/reactive. One lock serializes downstream delivery, and a separate lock guards only the cached latest value. The value sequence now updates the cached value under its own lock without waiting on downstream work, so a slow observer delays only further source elements, not value updates.Validation
Observable behavior is otherwise unchanged. The value sequence is subscribed before the source, so a synchronously available value is ready when the source emits immediately. The source observer forwards completion directly, so the result sequence completes with the source and no longer needs the
TakeUntilclause the previous composition added to fix #670. A completed value sequence retains its last value, and an error on either sequence faults downstream.WithLatestFromTestswas added to guard the behavior-preservation dimensions against regression: pairing with the latest value, source completion, value-sequence completion retaining the last value, dropping a source element that arrives before any value, faulting on either sequence, and synchronous value availability.Closes #2600