Skip to content

Commit ca811ee

Browse files
committed
Update README.md
1 parent d84b484 commit ca811ee

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

README.md

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@ SwiftTask
33

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

6-
(2014/08/23 Currently testing in Xcode6-beta5)
7-
86
![SwiftTask](Screenshots/diagram.png)
97

108

119
## Example
1210

1311
### Basic
1412

15-
```
13+
```swift
1614
// define task
1715
let task = Task<Float, String, NSError> { (progress, fulfill, reject, configure) in
1816

@@ -58,7 +56,8 @@ One of the best example would be [Alamofire](https://github.com/Alamofire/Alamof
5856
as seen below.
5957

6058
### Using [Alamofire](https://github.com/Alamofire/Alamofire)
61-
```
59+
60+
```swift
6261
typealias Progress = (bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64)
6362

6463
// define task
@@ -104,7 +103,7 @@ You can even use custom operators for chaining! :dizzy:
104103
- `task *** {...}` = `task.then { value in ...}` (fulfilled only)
105104
- `task !!! {...}` = `task.catch { errorInfo in ...}` (rejected only)
106105

107-
```
106+
```swift
108107
task ~ { (progress: Float) in
109108

110109
println("progress = \(progress)")
@@ -148,7 +147,7 @@ For more examples, please see XCTest cases.
148147

149148
Define your `task` inside `closure`.
150149

151-
```
150+
```swift
152151
let task = Task<Float, NSString?, NSError> { (progress, fulfill, reject, configure) in
153152

154153
player.doSomethingWithCompletion { (value: NSString?, error: NSError?) in
@@ -168,15 +167,15 @@ Optionally, you can call `progress(progressValue)` multiple times before calling
168167

169168
To add `pause`/`resume`/`cancel` functionality to your `task`, use `configure` to wrap up the original one.
170169

171-
```
170+
```swift
172171
configure.pause = { player.pause() }
173172
configure.resume = { player.resume() }
174173
configure.cancel = { player.cancel() }
175174
```
176175

177176
### task.progress(_ progressClosure:) -> task
178177

179-
```
178+
```swift
180179
task.progress { (progressValue: Progress) in
181180
println(progressValue)
182181
return
@@ -201,7 +200,7 @@ This case is similar to JavaScript's `promise.then(onFulfilled)`.
201200

202201
- `fulfilledClosure: Value -> Value2` (flow: *task => newTask*)
203202

204-
```
203+
```swift
205204
// task will be fulfilled with value "Hello"
206205

207206
task.then { (value: String) -> String in
@@ -214,7 +213,7 @@ This case is similar to JavaScript's `promise.then(onFulfilled)`.
214213
215214
- `fulfilledClosure: Value -> Task` (flow: *task => task2 => newTask*)
216215
217-
```
216+
```swift
218217
// task will be fulfilled with value "Hello"
219218
// task2 will be fulfilled with value "\() Swift"
220219
@@ -235,7 +234,7 @@ This case is similar to JavaScript's `promise.then(onFulfilled, onRejected)`.
235234

236235
- `thenClosure: (Value?, ErrorInfo?) -> Value2` (flow: *task => newTask*)
237236

238-
```
237+
```swift
239238
// task will be fulfilled with value "Hello"
240239

241240
task.then { (value: String?, errorInfo: ErrorInfo?) -> String in
@@ -254,7 +253,7 @@ This case is similar to JavaScript's `promise.then(onFulfilled, onRejected)`.
254253
255254
- `thenClosure: (Value?, ErrorInfo?) -> Task` (flow: *task => task2 => newTask*)
256255
257-
```
256+
```swift
258257
// task will be fulfilled with value "Hello"
259258
// task2 will be fulfilled with value "\(value) Swift"
260259
@@ -278,7 +277,7 @@ Similar to `task.then(fulfilledClosure)` for fulfilled only, `task.catch(catchCl
278277

279278
This case is similar to JavaScript's `promise.then(undefined, onRejected)` or `promise.catch(onRejected)`.
280279

281-
```
280+
```swift
282281
// task will be rejected with error "Oh My God"
283282

284283
task.then { (value: String) -> Void in

0 commit comments

Comments
 (0)