EMBreakDepedencyRealm icon indicating copy to clipboard operation
EMBreakDepedencyRealm copied to clipboard

Threads

Open zdnk opened this issue 7 years ago • 1 comments

I have read your article and I have a question regarding realm and threads. Your current implementation of RealmContxt is assuming it will be called just from the main thread I suppose. Well in many cases you want to make calls from other threads and have it actually do the work on other threads. How would you approach and achieve this with this model? I guess the same goes for CoreData and contexts.

zdnk avatar Jul 24 '17 07:07 zdnk

Hi @zdenektopic, After that article I've published StorageKit (https://github.com/StorageKit/storagekit).

You can take a look at https://github.com/StorageKit/StorageKit/blob/develop/Source/Storages/Realm/RealmDataStorage.swift and especially at the method getThreadSafeEntities.

The idea there is that you can "move" entities between threads in a safe way. In the example projects I've shown how to perform queries in background and getting data on the main thread.

With storagekit the goal is exactly to provide the same behavior to both realm and CoreData.

ennioma avatar Jul 24 '17 08:07 ennioma