Zhuinden / realm-monarchy

[ACTIVE-ISH] A wrapper over Realm which exposes it as LiveData, managing Realm lifecycle internally.
Apache License 2.0
88 stars 11 forks source link

Callbacks for Monarchy.writeAsync #25

Closed okycelt closed 5 years ago

okycelt commented 5 years ago

In one of our projects, we're using Realm.executeTransactionAsync() with onSuccess() and onError() callbacks. However, Monarchy's method writeAsync() doesn't have them. How would you suggest to do this with Monarchy?

Thanks in advance

Zhuinden commented 5 years ago

writeAsync runs the transaction on a single threaded executor, and the code that Realm uses to delay success/failure callbacks until the UI thread Realm has been updated is super-internal (I think it's an OSSchemaVersionCallback? Something like that) so by default my assumption is that you'll be notified of changes anyway via RealmChangeListeners on RealmResults

If you really need the ability to executeTransactionAsync with a UI thread callback once the bg thread has succeeded AND the UI thread has been updated, you'd need to go through a Realm instance directly, because it's not exposed to me in such a way that I'd find it reliable to use it in Monarchy.

okycelt commented 5 years ago

Okay, I understand. Just for the sake of completeness, the point of our use case is that we cache the time when data in Realm have been updated. I think RealmChangeListeners wouldn't be the right approach for this. I'm closing the issue as there's probably nothing to be done on the side of Monarchy.

Thanks for quick response