Skip to content

Add retryable feature. #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 5, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
SwiftTask
=========

[Promise](http://www.html5rocks.com/en/tutorials/es6/promises/) + progress + pause + cancel, using [SwiftState](https://github.com/inamiy/SwiftState) (state machine).
[Promise](http://www.html5rocks.com/en/tutorials/es6/promises/) + progress + pause + cancel + retry, using [SwiftState](https://github.com/inamiy/SwiftState) (state machine).

![SwiftTask](Screenshots/diagram.png)

### Ver 2.1.0 Changelog (2014/12/05)

- added **retryable** feature `try()`

### Ver 2.0.0 Changelog (2014/11/18)

- `task.progress()`'s `progressClosure` type changed from `Progress -> Void` to `(oldProgress: Progress?, newProgress: Progress) -> Void`
Expand Down Expand Up @@ -108,12 +112,30 @@ task.progress { (oldProgress: Progress?, newProgress: Progress) in
}
```

### Retry-able

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

This feature is extremely useful for unstable tasks e.g. network connection.
By implementing *retryable* from `SwiftTask`'s side, similar code is no longer needed for `player` (inner logic) class.

```swift
task.try(3).progress { ... }.success { ...
// this closure will be called even when task is rejected for 1st & 2nd try
// but finally fulfilled in 3rd try.
}

// shorthand
(task ~ 3).then { ... }
```

For more examples, please see XCTest cases.


## API Reference

### Task.init(closure:)
### Task.init(initClosure:)

Define your `task` inside `initClosure`.

Expand Down Expand Up @@ -243,6 +265,10 @@ task.success { (value: String) -> Void in
}
```

### task.try(_ tryCount:) -> newTask

See [Retry-able section](#retry-able).

### Task.all(_ tasks:) -> newTask

`Task.all(tasks)` is a new task that performs all `tasks` simultaneously and will be:
Expand Down
Loading