|
1 | 1 | SwiftTask
|
2 | 2 | =========
|
3 | 3 |
|
4 |
| -[Promise](http://www.html5rocks.com/en/tutorials/es6/promises/) + progress + pause + cancel, using [SwiftState](https://github.com/inamiy/SwiftState) (state machine). |
| 4 | +[Promise](http://www.html5rocks.com/en/tutorials/es6/promises/) + progress + pause + cancel + retry, using [SwiftState](https://github.com/inamiy/SwiftState) (state machine). |
5 | 5 |
|
6 | 6 | 
|
7 | 7 |
|
| 8 | +### Ver 2.1.0 Changelog (2014/12/05) |
| 9 | + |
| 10 | +- added **retryable** feature `try()` |
| 11 | + |
8 | 12 | ### Ver 2.0.0 Changelog (2014/11/18)
|
9 | 13 |
|
10 | 14 | - `task.progress()`'s `progressClosure` type changed from `Progress -> Void` to `(oldProgress: Progress?, newProgress: Progress) -> Void`
|
@@ -108,12 +112,30 @@ task.progress { (oldProgress: Progress?, newProgress: Progress) in
|
108 | 112 | }
|
109 | 113 | ```
|
110 | 114 |
|
| 115 | +### Retry-able |
| 116 | + |
| 117 | +From ver 2.1.0, `Task` is **retryable** for multiple times by using `try()` method ([Pull Request #9](https://github.com/ReactKit/SwiftTask/pull/9)). |
| 118 | +For example, `task.try(n)` will retry at most `n-1` times if `task` keeps rejected, and `task.try(1)` is obviously same as `task` itself having no retries. |
| 119 | + |
| 120 | +This feature is extremely useful for unstable tasks e.g. network connection. |
| 121 | +By implementing *retryable* from `SwiftTask`'s side, similar code is no longer needed for `player` (inner logic) class. |
| 122 | + |
| 123 | +```swift |
| 124 | +task.try(3).progress { ... }.success { ... |
| 125 | + // this closure will be called even when task is rejected for 1st & 2nd try |
| 126 | + // but finally fulfilled in 3rd try. |
| 127 | +} |
| 128 | + |
| 129 | +// shorthand |
| 130 | +(task ~ 3).then { ... } |
| 131 | +``` |
| 132 | + |
111 | 133 | For more examples, please see XCTest cases.
|
112 | 134 |
|
113 | 135 |
|
114 | 136 | ## API Reference
|
115 | 137 |
|
116 |
| -### Task.init(closure:) |
| 138 | +### Task.init(initClosure:) |
117 | 139 |
|
118 | 140 | Define your `task` inside `initClosure`.
|
119 | 141 |
|
@@ -243,6 +265,10 @@ task.success { (value: String) -> Void in
|
243 | 265 | }
|
244 | 266 | ```
|
245 | 267 |
|
| 268 | +### task.try(_ tryCount:) -> newTask |
| 269 | +
|
| 270 | +See [Retry-able section](#retry-able). |
| 271 | +
|
246 | 272 | ### Task.all(_ tasks:) -> newTask
|
247 | 273 |
|
248 | 274 | `Task.all(tasks)` is a new task that performs all `tasks` simultaneously and will be:
|
|
0 commit comments