Skip to content

Instantly share code, notes, and snippets.

@littlebobert
Last active March 3, 2017 02:09
Show Gist options
  • Save littlebobert/37d68ea540e86c2f4ed8c25d0ff13601 to your computer and use it in GitHub Desktop.
Save littlebobert/37d68ea540e86c2f4ed8c25d0ff13601 to your computer and use it in GitHub Desktop.
// before the change
BAPromise *promise = [self methodThatReturnsAPromise];
[promise then:^id(id obj) {
NSLog(@"1st");
return [[self otherMethodThatReturnsAPromise] then:^id(id obj) {
NSLog(@"2nd");
return obj;
}];
}];
[promise done:^(id obj) {
NSLog(@"3rd");
}];
// after the change
BAPromise *promise = [self methodThatReturnsAPromise];
[promise then:^id(id obj) {
NSLog(@"1st");
return obj;
}];
[promise then:^id(id obj) {
NSLog(@"2nd");
return [[self otherMethodThatReturnsAPromise] then:^id(id obj) {
NSLog(@"4th");
return obj;
}];
}];
[promise done:^(id obj) {
NSLog(@"3rd");
}];
// fix
BAPromise *promise = [self methodThatReturnsAPromise];
[promise then:^id(id obj) {
NSLog(@"1st");
return obj;
}];
[promise then:^id(id obj) {
NSLog(@"2nd");
BAPromise *promise2 = [[self otherMethodThatReturnsAPromise] then:^id(id obj) {
NSLog(@"3rd");
return obj;
}];
[promise2 done:^(id obj) {
NSLog(@"4th");
}];
return promise2;
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment