Created
February 3, 2015 05:55
-
-
Save akisute/ee17463f862a334731c4 to your computer and use it in GitHub Desktop.
TaskToken to cancel running tasks with BFTask
This file contains 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
- (BFTask *)loadSomeDataWithToken:(TaskToken *)token | |
{ | |
BFTask *getSomeDataTask; | |
BFTask *getOtherDataTask; | |
getSomeDataTask = [[APIClient sharedClient] withToken:token executeAPI:^BFTask *(APIClient *client) { | |
return [[client getSomeDataWithParameters:@{}] continueWithSuccessBlock:^id(BFTask *task) { | |
// TODO: do something | |
return task; | |
}]; | |
}]; | |
getSomeDataTask = [[APIClient sharedClient] withToken:token executeAPI:^BFTask *(APIClient *client) { | |
return [[client getOtherDataWithParameters:@{@"user": @"akisute"}] continueWithSuccessBlock:^id(BFTask *task) { | |
// TODO: do other thing | |
return task; | |
}]; | |
}]; | |
return [BFTask taskForCompletionOfAllTasks:@[getSomeDataTask, getOtherDataTask]]; | |
} | |
- (void)doSomethingInSomewhere | |
{ | |
self.token = [TaskToken token]; | |
[[self loadSomeDataWithToken:token] continueWithSuccessBlock:^id(BFTask *task) { | |
// TODO: update data | |
self.token = nil; | |
return task; | |
}]; | |
} | |
- (void)cancelLoading | |
{ | |
if (self.token) { | |
[self.token cancel]; | |
self.token = nil; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment