Skip to content

Commit f7f65de

Browse files
author
David Poll
committed
Merge branch 'master' of github.com:BoltsFramework/Bolts-iOS
Conflicts: Readme.md
2 parents f4eb5ed + e37415c commit f7f65de

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ disclosure of security bugs. In those cases, please go through the process
2727
outlined on that page and do not file a public issue.
2828

2929
## Coding Style
30-
* Most importantly, match the exiting code style as much as possible.
30+
* Most importantly, match the existing code style as much as possible.
3131
* Try to keep lines under 100 characters, if possible.
3232

3333
## License

Readme.md

+27-1
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,32 @@ For common cases, such as dispatching on the main thread, we have provided defau
262262
}];
263263
```
264264

265+
## Task Cancellation
266+
267+
It's generally bad design to keep track of the `BFTaskCompletionSource` for cancellation. A better model is to create a "cancellation token" at the top level, and pass that to each async function that you want to be part of the same "cancelable operation". Then, in your continuation blocks, you can check whether the cancellation token has been cancelled and bail out early by returning a `[BFTask cancelledTask]`. For example:
268+
269+
```objective-c
270+
- (void)doSomethingComplicatedAsync:(MYCancellationToken *)cancellationToken {
271+
[[self doSomethingAsync:cancellationToken] continueWithBlock:^{
272+
if (cancellationToken.isCancelled) {
273+
return [BFTask cancelledTask];
274+
}
275+
// Do something that takes a while.
276+
return result;
277+
}];
278+
}
279+
280+
// Somewhere else.
281+
MYCancellationToken *cancellationToken = [[MYCancellationToken alloc] init];
282+
[obj doSomethingComplicatedAsync:cancellationToken];
283+
284+
// When you get bored...
285+
[cancellationToken cancel];
286+
```
287+
288+
**Note:** The cancellation token implementation should be thread-safe.
289+
We are likely to add some concept like this to Bolts at some point in the future.
290+
265291
# App Links
266292
267293
[App Links](http://www.applinks.org) provide a cross-platform mechanism that allows a developer to define and publish a deep-linking scheme for their content, allowing other apps to link directly to an experience optimized for the device they are running on. Whether you are building an app that receives incoming links or one that may link out to other apps' content, Bolts provides tools to simplify implementation of the [App Links protocol](http://www.applinks.org/documentation).
@@ -395,4 +421,4 @@ You can download the latest framework files from our [Releases page](https://git
395421

396422
Bolts is also available through [CocoaPods](http://cocoapods.org). To install it simply add the following line to your Podfile:
397423

398-
pod "Bolts"
424+
pod 'Bolts'

0 commit comments

Comments
 (0)