Skip to content

Instantly share code, notes, and snippets.

@ahinz
Created March 13, 2012 19:19
Show Gist options
  • Save ahinz/2030889 to your computer and use it in GitHub Desktop.
Save ahinz/2030889 to your computer and use it in GitHub Desktop.
CM
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