How is query execution performed in the background "when possible"?


#1

I use Realm for a long time, but I have fundamental questions to answer.

From the RealmSwift docs:

with the query execution performed on a background thread when possible.

So, a statement like this can be non-blocking, right?

let dogs = realm.objects(Dog.self) // Can be async?

What if I immediately access the results? Does Realm block the current thread if the read access was requested too early (i.e. before the Results are ready)?

Thanks.


#2

This operation is blocking. What the documentation tries to say is that when changes happen to the Realm from another thread, the query will need to be reevaluated to check if there are any changes and to trigger the notification blocks that have been registered with this query. This reevaluation is what happens on a background thread when possible.