-
Notifications
You must be signed in to change notification settings - Fork 167
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 WriteAsync wait for changes asynchronously #1729
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Realm/Realm/Realm.cs
Outdated
}).ContinueWith(_ => Refresh(), scheduler); | ||
}).ContinueWith(_ => | ||
{ | ||
if (otherVersion == SharedRealmHandle.GetTransactionVersion()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be strict equality? I imagine if the current version is higher (for some reason) than the other version, we should still return?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I’ll change the comparison.
Realm/Realm/Realm.cs
Outdated
RealmChangedEventHandler handler = null; | ||
handler = (sender, e) => | ||
{ | ||
((Realm)sender).RealmChanged -= handler; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit hazy on the subtleties of doing it like this (via the sender
) rather than unsubscribing this.RealmChanged
. Is it to avoid capturing this
in the closure and what would the harm be if we did capture it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly - I didn’t want to capture this
and create a reference cycle. If we capture it and the wvent never fires then the realm will leak.
Realm/Realm/Realm.cs
Outdated
/// Waits for the realm and outstanding objects to be updated to a newer version. | ||
/// </summary> | ||
/// <returns>An awaitable <see cref="Task"/>.</returns> | ||
private Task WaitForChangesAsync() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope you don't mind a comment from an outsider. Could you consider making this public? And why the change in name compared to Refresh
? I would expect it to be called RefreshAsync
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm.. I think I get it. You need to compare the current transaction version number with something, to avoid waiting in vane for a change that may never come. Is it not possible to query the realm for the highest transaction version seen?
@tgoyne I added you as a reviewer to give your opinion on the high-level approach and confirm whether it matches what we discussed, thanks. |
872bd28
to
df3c670
Compare
* c++ portion * Use has_changed rather than the transaction version explicitly * Changelog
7a98d08
to
246d8d7
Compare
Description
Fixes #1728
TODO