Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

completion block is not called when MR_saveInBackgroundErrorHandler:completion: is called on a child of the default context #221

Closed
wants to merge 1 commit into from

Conversation

blackgold9
Copy link
Contributor

It's currently only going to be called if it's saving the root context. calling it on the default queue causes it to save the root queue (and hence trigger the callback). If you use a child of the default context, it does not get called.
As a result saveInBackgroundWithBlock:completion:errorHandler: (in actions) never fires it's callback because it uses a child context, which is neither the default nor root context.

(hope that was understandable)

@peterpaulis
Copy link

fixed with

- (void) MR_saveInBackgroundErrorHandler:(void (^)(NSError *))errorCallback completion:(void (^)(void))completion;
{
    [self performBlockAndWait:^{
        [self MR_saveWithErrorCallback:errorCallback];

        if (self == [[self class] MR_defaultContext])
        {
            [[[self class] MR_rootSavingContext] MR_saveInBackgroundErrorHandler:errorCallback completion:completion];
        } 
        else if (completion)
        {
            dispatch_async(dispatch_get_main_queue(), completion);
        }
    }];
}

@andrewgarn
Copy link

I had the same issue with saveInBackgroundWithBlock. Thanks @xelvenone

@mammo
Copy link

mammo commented Aug 24, 2012

Thank you, @xelvenone! This caused me much confusion!

@blackgold9
Copy link
Contributor Author

Fixed by a more tested commit

@blackgold9 blackgold9 closed this Sep 6, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants