magicalpanda / MagicalRecord

Super Awesome Easy Fetching for Core Data!
Other
10.8k stars 1.79k forks source link

Syncing main thread with background save threads #930

Open killerham opened 9 years ago

killerham commented 9 years ago

Hello,

What is the best way for me to sync the background saving threads that are created from the [MagicalRecord saveWithBlock:^] functions with the main thread?

The reason I need to do this is because I want to wait until all of the saves are guaranteed to be completed before closing the document. This is to prevent long background saves from occurring while the document is closed.

I've tried calling [MagicalRecord saveWithBlockAndWait:^] when exiting the document, but it seems to not be waiting for the entire background queue to complete.

Thanks

Alydyn commented 9 years ago

This is more of a stack overflow question than github. The MR team would like github to be used for actual code issues and stack overflow to be used for support. That being said, it's pretty tough to answer that question without a lot more info. However, in general, you would probably have better luck using NSOperation's and an NSOperationQueue, and utilize completion blocks and/or operation dependencies.

waltermvp commented 9 years ago

@killerham if you create a SO question please provide the link as I'm interested in possible answers for this question. Thanks