Skip to content

Commit 113dae4

Browse files
committed
Merge pull request #9 from ReactKit/retryable
Add retryable feature.
2 parents bdf910d + 8a7fd3c commit 113dae4

File tree

6 files changed

+689
-83
lines changed

6 files changed

+689
-83
lines changed

README.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
SwiftTask
22
=========
33

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).
55

66
![SwiftTask](Screenshots/diagram.png)
77

8+
### Ver 2.1.0 Changelog (2014/12/05)
9+
10+
- added **retryable** feature `try()`
11+
812
### Ver 2.0.0 Changelog (2014/11/18)
913

1014
- `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
108112
}
109113
```
110114

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+
111133
For more examples, please see XCTest cases.
112134

113135

114136
## API Reference
115137

116-
### Task.init(closure:)
138+
### Task.init(initClosure:)
117139

118140
Define your `task` inside `initClosure`.
119141

@@ -243,6 +265,10 @@ task.success { (value: String) -> Void in
243265
}
244266
```
245267
268+
### task.try(_ tryCount:) -> newTask
269+
270+
See [Retry-able section](#retry-able).
271+
246272
### Task.all(_ tasks:) -> newTask
247273
248274
`Task.all(tasks)` is a new task that performs all `tasks` simultaneously and will be:

0 commit comments

Comments
 (0)