Skip to content
This repository has been archived by the owner on Oct 29, 2021. It is now read-only.

Commit

Permalink
Renaming undone.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexruperez committed Sep 11, 2018
1 parent 645363a commit 07f1155
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 82 deletions.
14 changes: 7 additions & 7 deletions KommanderTests/DispatcherTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ class DispatcherTests: XCTestCase {
}

func testDefaultDispatcherOperationQueue() {
let operation = dispatcher.run({ sleep(2) })
let operation = dispatcher.execute({ sleep(2) })
XCTAssertGreaterThan(dispatcher.operationQueue.operationCount, 0)
operation.cancel()
XCTAssertTrue(operation.isCancelled)
}

func testDefaultDispatcherDispatchQueue() {
let dispatchWorkItem = DispatchWorkItem(qos: .default, flags: .assignCurrentContext) { sleep(2) }
dispatcher.run(dispatchWorkItem)
dispatcher.execute(dispatchWorkItem)
XCTAssertFalse(dispatchWorkItem.isCancelled)
dispatchWorkItem.cancel()
XCTAssertTrue(dispatchWorkItem.isCancelled)
Expand All @@ -52,15 +52,15 @@ class DispatcherTests: XCTestCase {
XCTAssertEqual(dispatcher.operationQueue.name, randomName)
XCTAssertEqual(dispatcher.operationQueue.maxConcurrentOperationCount, 1)
XCTAssertEqual(dispatcher.operationQueue.qualityOfService, .background)
let operation = dispatcher.run({ sleep(2) })
let operation = dispatcher.execute({ sleep(2) })
XCTAssertGreaterThan(dispatcher.operationQueue.operationCount, 0)
operation.cancel()
XCTAssertTrue(operation.isCancelled)
}

func testMainDispatcherOperationQueue() {
dispatcher = .main
let operation = dispatcher.run({ sleep(2) })
let operation = dispatcher.execute({ sleep(2) })
XCTAssertEqual(dispatcher.operationQueue, OperationQueue.main)
XCTAssertGreaterThan(dispatcher.operationQueue.operationCount, 0)
operation.cancel()
Expand All @@ -70,7 +70,7 @@ class DispatcherTests: XCTestCase {
func testMainDispatcherDispatchQueue() {
dispatcher = .main
let dispatchWorkItem = DispatchWorkItem(qos: .default, flags: .assignCurrentContext) { sleep(2) }
dispatcher.run(dispatchWorkItem)
dispatcher.execute(dispatchWorkItem)
XCTAssertEqual(dispatcher.dispatchQueue, DispatchQueue.main)
XCTAssertFalse(dispatchWorkItem.isCancelled)
dispatchWorkItem.cancel()
Expand All @@ -81,7 +81,7 @@ class DispatcherTests: XCTestCase {
let operationQueue = OperationQueue()
operationQueue.addOperation {
self.dispatcher = .current
let operation = self.dispatcher.run({ sleep(2) })
let operation = self.dispatcher.execute({ sleep(2) })
XCTAssertGreaterThan(self.dispatcher.operationQueue.operationCount, 0)
operation.cancel()
XCTAssertTrue(operation.isCancelled)
Expand All @@ -93,7 +93,7 @@ class DispatcherTests: XCTestCase {
dispatchQueue.async {
self.dispatcher = .current
let dispatchWorkItem = DispatchWorkItem(qos: .default, flags: .assignCurrentContext) { sleep(2) }
self.dispatcher.run(dispatchWorkItem)
self.dispatcher.execute(dispatchWorkItem)
XCTAssertFalse(dispatchWorkItem.isCancelled)
dispatchWorkItem.cancel()
XCTAssertTrue(dispatchWorkItem.isCancelled)
Expand Down
34 changes: 17 additions & 17 deletions KommanderTests/KommanderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class KommanderTests: XCTestCase {
.error({ (error) in
ex.fulfill()
XCTFail()
}).run()
}).execute()

waitForExpectations(timeout: 100, handler: nil)
}
Expand All @@ -54,7 +54,7 @@ class KommanderTests: XCTestCase {
.error({ (error) in
ex.fulfill()
XCTFail()
}).run()
}).execute()

let k2 = interactor.getCounter(name: "C2", to: 5)
.success({ (name) in
Expand All @@ -66,10 +66,10 @@ class KommanderTests: XCTestCase {
.error({ (error) in
ex.fulfill()
XCTFail()
}).run()
}).execute()

k1.run()
k2.run()
k1.execute()
k2.execute()

waitForExpectations(timeout: 100, handler: nil)
}
Expand All @@ -93,7 +93,7 @@ class KommanderTests: XCTestCase {
ex.fulfill()
XCTFail()
})
.run(after: .seconds(1))
.execute(after: .seconds(1))
}

waitForExpectations(timeout: 100, handler: nil)
Expand All @@ -118,7 +118,7 @@ class KommanderTests: XCTestCase {
ex.fulfill()
}
})
.run()
.execute()
.cancel(true, after: .seconds(2))
}

Expand All @@ -145,7 +145,7 @@ class KommanderTests: XCTestCase {
ex.fulfill()
XCTFail()
})
.run()
.execute()
.cancel(false, after: .seconds(2))
.retry(after: .seconds(5))
}
Expand Down Expand Up @@ -181,7 +181,7 @@ class KommanderTests: XCTestCase {
let secondRecoverySuccess = error.attemptRecovery(optionIndex: 0)
XCTAssertFalse(secondRecoverySuccess)
})
.run()
.execute()
.cancel(true, after: .seconds(2))
}

Expand All @@ -196,7 +196,7 @@ class KommanderTests: XCTestCase {
var executions = 0
let retries = Int(arc4random_uniform(10) + 1)

kommander.do({
kommander.make({
print("Execution: \(executions)")
if throwingError {
throw CocoaError(.featureUnsupported)
Expand All @@ -217,7 +217,7 @@ class KommanderTests: XCTestCase {
}
executions += 1
return true
}).run()
}).execute()

waitForExpectations(timeout: 100, handler: nil)
}
Expand All @@ -241,7 +241,7 @@ class KommanderTests: XCTestCase {
ex.fulfill()
XCTFail()
})
.run()
.execute()
}

waitForExpectations(timeout: 100, handler: nil)
Expand Down Expand Up @@ -270,7 +270,7 @@ class KommanderTests: XCTestCase {
}))
}

interactor.kommander.run(kommands, concurrent: true, waitUntilFinished: true)
interactor.kommander.execute(kommands, concurrent: true, waitUntilFinished: true)

waitForExpectations(timeout: 100, handler: nil)
}
Expand Down Expand Up @@ -298,7 +298,7 @@ class KommanderTests: XCTestCase {
}))
}

interactor.kommander.run(kommands, concurrent: true, waitUntilFinished: false)
interactor.kommander.execute(kommands, concurrent: true, waitUntilFinished: false)

waitForExpectations(timeout: 100, handler: nil)
}
Expand Down Expand Up @@ -326,7 +326,7 @@ class KommanderTests: XCTestCase {
}))
}

interactor.kommander.run(kommands, concurrent: false, waitUntilFinished: true)
interactor.kommander.execute(kommands, concurrent: false, waitUntilFinished: true)

waitForExpectations(timeout: 100, handler: nil)
}
Expand Down Expand Up @@ -354,7 +354,7 @@ class KommanderTests: XCTestCase {
}))
}

interactor.kommander.run(kommands, concurrent: false, waitUntilFinished: false)
interactor.kommander.execute(kommands, concurrent: false, waitUntilFinished: false)

waitForExpectations(timeout: 100, handler: nil)
}
Expand Down Expand Up @@ -386,7 +386,7 @@ extension KommanderTests {
}

func getCounter(name: String, to: Int) -> Kommand<String> {
return kommander.do({ () -> String in
return kommander.make({ () -> String in
print ("\(name) Starts")
var cont = 0
while cont < to {
Expand Down
16 changes: 8 additions & 8 deletions Major/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ class ViewController: UIViewController {
let sleepTime: UInt32 = 2

@IBAction func singleAction(_ sender: UIButton) {
kommander.do { () -> TimeInterval in
kommander.make { () -> TimeInterval in
sleep(self.sleepTime)
return Date().timeIntervalSince1970
}.success { result in
print("Single: " + String(describing: result))
}.run()
}.execute()
}

@IBAction func concurrentAction(_ sender: UIButton) {
kommander.run(kommander.do([ { () -> Any? in
kommander.execute(kommander.make([ { () -> Any? in
sleep(self.sleepTime)
print("Concurrent first: " + String(describing: Date().timeIntervalSince1970))
return nil
Expand All @@ -40,7 +40,7 @@ class ViewController: UIViewController {
}

@IBAction func sequentialAction(_ sender: UIButton) {
kommander.run(kommander.do([ { () -> Any? in
kommander.execute(kommander.make([ { () -> Any? in
sleep(self.sleepTime)
print("Sequential first: " + String(describing: Date().timeIntervalSince1970))
return nil
Expand All @@ -56,18 +56,18 @@ class ViewController: UIViewController {
}

@IBAction func errorAction(_ sender: UIButton) {
kommander.do {
kommander.make {
sleep(self.sleepTime)
throw CocoaError(.featureUnsupported)
}.error(CocoaError.self) {
print("Error: " + $0.localizedDescription)
}.run()
}.execute()
}

@IBAction func crashAction(_ sender: UIButton) {
kommander.do {
kommander.make {
sleep(self.sleepTime)
fatalError()
}.run()
}.execute()
}
}
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,53 +90,53 @@ dependencies: [
#### Making, executing, cancelling and retrying Kommands:

```swift
Kommander().do {
Kommander().make {
// Your code here
}.run()
}.execute()
```

```swift
Kommander().do {
Kommander().make {
// Your code here
}.run(after: .seconds(2))
}.execute(after: .seconds(2))
```

```swift
Kommander().do {
Kommander().make {
return "Your string"
}.success { yourString in
print(yourString)
}.run()
}.execute()
```

```swift
Kommander().do {
Kommander().make {
throw CocoaError(.featureUnsupported)
}.error { error in
print(String(describing: error!))
}.run()
}.execute()
```

##### Specify Error type:

```swift
Kommander().do {
Kommander().make {
throw MyError.error
}.error(MyError.self) { error in
// error is MyError type.
}.run()
}.execute()
```

##### Retry after cancellation:

```swift
let kommand = Kommander().do { () -> Any? in
let kommand = Kommander().make { () -> Any? in
// Your code here
}.success { result in
// Your success handling here
}.error { error in
// Your error handling here
}.run()
}.execute()

kommand.cancel()

Expand All @@ -146,13 +146,13 @@ kommand.retry()
##### Retry after failure:

```swift
let kommand = Kommander().do { () -> Any? in
let kommand = Kommander().make { () -> Any? in
// Your code here
}.error { error in
// Your error handling here
}.retry { error, executionCount in
return executionCount < 2
}.run()
}.execute()
```

#### Creating Kommanders:
Expand Down
Loading

0 comments on commit 07f1155

Please sign in to comment.