Skip to content

Commit d127eed

Browse files
committed
Rename try() to retry()
1 parent bbff1f2 commit d127eed

File tree

2 files changed

+11
-25
lines changed

2 files changed

+11
-25
lines changed

SwiftTask/SwiftTask.swift

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -311,17 +311,17 @@ public class Task<Progress, Value, Error>: Cancellable, CustomStringConvertible
311311
return clonedTask
312312
}
313313

314-
/// Returns new task that is retryable for `maxTryCount-1` times.
315-
public func `try`(maxTryCount: Int) -> Task
314+
/// Returns new task that is retryable for `maxRetryCount (= maxTryCount-1)` times.
315+
public func retry(maxRetryCount: Int) -> Task
316316
{
317-
if maxTryCount < 2 { return self }
317+
if maxRetryCount < 1 { return self }
318318

319319
return Task { machine, progress, fulfill, _reject, configure in
320320

321321
let task = self.progress { _, progressValue in
322322
progress(progressValue)
323323
}.failure { [unowned self] _ -> Task in
324-
return self.clone().`try`(maxTryCount-1) // clone & try recursively
324+
return self.clone().retry(maxRetryCount-1) // clone & try recursively
325325
}
326326

327327
task.progress { _, progressValue in
@@ -345,7 +345,7 @@ public class Task<Progress, Value, Error>: Cancellable, CustomStringConvertible
345345
self.cancel()
346346
}
347347

348-
}.name("\(self.name)-try(\(maxTryCount))")
348+
}.name("\(self.name)-try(\(maxRetryCount))")
349349
}
350350

351351
///
@@ -790,18 +790,4 @@ extension Task
790790
task.resume()
791791
}
792792
}
793-
}
794-
795-
//--------------------------------------------------
796-
// MARK: - Custom Operators
797-
// + - * / % = < > ! & | ^ ~ .
798-
//--------------------------------------------------
799-
800-
infix operator ~ { associativity left }
801-
802-
/// abbreviation for `try()`
803-
/// e.g. (task ~ 3).then { ... }
804-
public func ~ <P, V, E>(task: Task<P, V, E>, tryCount: Int) -> Task<P, V, E>
805-
{
806-
return task.`try`(tryCount)
807793
}

SwiftTaskTests/SwiftTaskTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -791,9 +791,9 @@ class SwiftTaskTests: _TestCase
791791
}
792792
}
793793

794-
}.`try`(maxTryCount).failure { errorInfo -> String in
794+
}.retry(maxTryCount-1).failure { errorInfo -> String in
795795

796-
XCTFail("Should never reach here because `task.retry(\(maxTryCount))` will be fulfilled on retry[\(fulfilledTryCount)] even though retry[1...\(fulfilledTryCount-1)] will be rejected.")
796+
XCTFail("Should never reach here because `task.retry(\(maxTryCount-1))` will be fulfilled at `fulfilledTryCount` try even though previous retries will be rejected.")
797797

798798
return "DUMMY"
799799

@@ -825,7 +825,7 @@ class SwiftTaskTests: _TestCase
825825
reject("ERROR \(actualTryCount)")
826826
}
827827

828-
}.`try`(maxTryCount).failure { error, isCancelled -> String in
828+
}.retry(maxTryCount-1).failure { error, isCancelled -> String in
829829

830830
XCTAssertEqual(error!, "ERROR \(actualTryCount)")
831831
XCTAssertFalse(isCancelled)
@@ -867,7 +867,7 @@ class SwiftTaskTests: _TestCase
867867
}
868868
}
869869

870-
}.`try`(maxTryCount).progress { _ in
870+
}.retry(maxTryCount-1).progress { _ in
871871

872872
progressCount++
873873

@@ -927,7 +927,7 @@ class SwiftTaskTests: _TestCase
927927
return
928928
}
929929

930-
}.`try`(maxTryCount)
930+
}.retry(maxTryCount-1)
931931

932932
retryableTask.success { value -> Void in
933933

@@ -979,7 +979,7 @@ class SwiftTaskTests: _TestCase
979979

980980
}
981981

982-
let retryableTask = task.`try`(maxTryCount)
982+
let retryableTask = task.retry(maxTryCount-1)
983983

984984
retryableTask.success { value -> Void in
985985

0 commit comments

Comments
 (0)