Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@JakenVeina
Copy link
Collaborator

Added a shared/reusable implementation for multi-locking within stream operators, I.E. being able to process upstream notifications and downstream notifications at the same time, with different locks, while still preserving notification order.

I've been testing this strategy for locking within the new .Filter() operators I'm working on. Usage of this class in that case would look like....

private void OnNext(IChangeSet<T> changes)
{
    using var @lock = SwappableLock.CreateAndEnter(UpstreamSynchronizationGate);
    
    foreach (var change in changes)
    {
        ...
    }
    
    var downstreamChanges = ChangeSet<T>.Empty;
    if (_downstreamChangesBuffer.Count is not 0)
    {
        downstreamChanges = new ChangeSet<T>(_downstreamChangesBuffer);
        _downstreamChangesBuffer.Clear();
    }
 
    if ((downstreamChanges.Count is not 0) || !_suppressEmptyChangeSets)
    {
        @lock.SwapTo(DownstreamSynchronizationGate);
        
        _downstreamObserver.OnNext(downstreamChanges);
    }
}

…m operators, I.E. being able to process upstream notifications and downstream notifications at the same time, with different locks, while still preserving notification order.
@dwcullop
Copy link
Member

Why would you need this? Is it as an optimization?

@JakenVeina
Copy link
Collaborator Author

Why would you need this? Is it as an optimization?

Yes. Nothing specifically more than that.

Copy link
Collaborator

@RolandPheasant RolandPheasant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I .wrote DD, I was looking for something like this but never got it quite right. Looking forward to seeing it in action

@JakenVeina JakenVeina merged commit a02c6d6 into main May 22, 2024
@JakenVeina JakenVeina deleted the feature/upstream-downstream-locking branch May 22, 2024 05:46
@github-actions
Copy link

github-actions bot commented Jun 6, 2024

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants