Can I have the toFlow() in the background thread?

Is it possible to have a Kotlin Flow created out of a Realm query be 100% in a background thread?

For example, nowadays I have something like this in a few places:

val myListFlow = Realm.getDefaultInstance()
.where(MyRealmModel::class.java)
.findAllAsync()
.toFlow()
.filter {it.isValid}
.flowOn(Dispatchers.Main)
.map {
it.toList()
}
.flowOn(Dispatchers.IO)

And I’m starting to get performance issues (ANRs) because it takes too long, so I’d like to move the entire thing to the background thread, Dispatchers.IO is that even possible? Please correct me, but I understand that the Realm queries are supposed to run in the same thread the Realm instance was instantiated – so if I want the whole query to run in the background thread, I need somehow to instantiate the Realm instante in the background thread?

Thanks,