MR_saveNestedContextsErrorHandler:completion: only executes on background threads #311

Closed
jmca opened this Issue Nov 15, 2012 · 2 comments

Projects

None yet

2 participants

@jmca
jmca commented Nov 15, 2012

Is it a bad architecture choice for small data writes to save nested contexts on the main thread? I noticed that MR_saveNestedContextsErrorHandler:completion: was saving my nested contexts on a background thread which was causing me some issues while fetching before the parent context was updated.

Since there is the method MR_saveInBackgroundErrorHandler:completion, I would assume that MR_saveNestedContextsErrorHandler:completion: would NOT be executed on background threads. Or there should be an equivalent MR_saveNestedContextsInBackgroundErrorHandler:completion method.

This is MR_saveNestedContextsErrorHandler:completion: executing off the main thread:

- (void) MR_saveNestedContextsErrorHandler:(void (^)(NSError *))errorCallback completion:(void (^)(void))completion;
{
    //[self performBlock:^{
    [self performBlockAndWait:^{
        [self MR_saveWithErrorCallback:errorCallback];
        if (self.parentContext) {
          // [[self parentContext] performBlock:^{
                [[self parentContext] MR_saveNestedContextsErrorHandler:errorCallback completion:completion];
           // }];
        } else {
            if (completion) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    completion();
                });
            }
        }
    }];
}

Would this cause unforeseen issues or lockups?

@blackgold9
Member

If you perform your fetch after the nested context save is complete it should be fine.
If you're using 2.0.8 there's a commit on develop that may help with any problems you've been having.

That said, we're looking into making this simpler.

@jmca jmca closed this Nov 15, 2012
@jmca
jmca commented Nov 15, 2012

Got it, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment