Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make UpdateAtomic Delegates scoped and distinct #10673

Merged
merged 1 commit into from
Nov 19, 2021
Merged

Conversation

jtkech
Copy link
Member

@jtkech jtkech commented Nov 8, 2021

Fixes #10672

Related to IVolatileDocumentManager.UpdateAtomicAsync() that for now is never used in OC.

  • One problem since we made IVolatileDocumentManager a singleton is that the same delegate list is always used / executed and grow up, so the delegate list should be still held at the scope level which I forgot to do.

  • The 2nd problem is when enlisting multiple delegates (not allowed with UpdateAsync()), we can enlist multiple time the same delegate (targetting the same method and so on), not a problem most of the time but not good when we do things by batches where the same one can be added many times, so the delegate list should only contain distinct delegates.

@@ -82,5 +88,11 @@ public Task UpdateAtomicAsync(Func<Task<TDocument>> updateAsync, Func<TDocument,

return Task.CompletedTask;
}

private class UpdateDelegates
Copy link
Member

Choose a reason for hiding this comment

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

That is called a Tuple, there are nice syntaxes in C# for that, and you can even do a struct record otherwise, but tuples are better here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes good ideas

But for the struct, I'm using a GetOrCreateFeature() that is waiting for a class, then for the tuple, because we can pass a factory I also tried a Tuple.Create<UpdateDelegate, AfterUpdateDelegate>(null, null)), but then we can't do delegates.Item1 += () => updateAsync() as it is readonly.

@jtkech jtkech merged commit bd292f5 into main Nov 19, 2021
@jtkech jtkech deleted the jtkech/scoped-delegate branch November 19, 2021 05:33
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.

Make UpdateAtomic Delegates scoped and distinct
2 participants