ennioma / EMBreakDepedencyRealm

https://medium.com/@EnnioMa/isolating-db-layer-dependency-for-a-better-app-architecture-a-use-case-with-realm-8255fa374c01
GNU General Public License v3.0
18 stars 1 forks source link

Threads #1

Open zdnk opened 7 years ago

zdnk commented 7 years ago

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.

ennioma commented 7 years ago

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.