-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Unknown
-
None
-
Affects Version/s: None
-
Component/s: None
Consider the following test code:
val realm = Realm.getInstance(config2)
realm.syncSession.downloadAllServerChanges()
// realm.refresh() Required for below code to work
assertEquals(10, realm.where<SyncDog>().count())
assertEquals(1, realm.where<SyncPerson>().count())
By reading it you would assume it would work, but it doesn't. The reason is that downloadAllServerChanges run on the Sync Client worker thread and when it completes the caller thread has not been updated yet.
Instead, you manually need to add a realm.refresh() after calling download().
We should consider doing that automatically. Realms normally using this API are not looper threads, so we don't need to be particularly worried about callbacks.
The only annoying thing is that the Session and Realm are largely uncoupled. The session is e.g. not thread confined, while the Realm is. So we need a clever way of finding any open Realms on the current thread, and there might be multiple (think typed and Dynamic Realm).
But maybe this is just too confusing...something to ponder.