Created
March 13, 2012 19:19
-
-
Save ahinz/2030889 to your computer and use it in GitHub Desktop.
CM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CMUser* user = [[CMUser alloc] initWithUsername:@"jim" password:@"pw"]; | |
Recipe* r = [[Recipe alloc] initWithUser:... name:.....]; | |
Review* rv = [[Review alloc] initWithUser:user recipe:r stars:5]; | |
CMFuture* future = [user saveFuture]; | |
CMFuture* future2 = [future andThen:^{ return [r saveFuture]; }]; | |
CMFuture* future3 = [future andThen:^{ return [rv saveFuture]; }]; | |
// or: future3 = | |
// [CMFuture doSeq:^{ return [user saveFuture]; }, | |
// ^{ return [r saveFuture]; }, | |
// ^{ return [rv saveFuture]; },nil]; | |
// If any of the futures fail for any reason, rollback the entire transaction | |
// all or nothing | |
[future3 execWithCallback:^(CMFutureStatus status, NSArray* messages, NSDictionary* statuses){ | |
if (status == CMFutureFailed) { | |
[Util showCMFailAlerts(messages); | |
} else { | |
[Util showObjectSavedOK(statuses); | |
}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment