diff --git a/CHANGELOG.md b/CHANGELOG.md index 96b6f8f..fc8c28b 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# Release 0.9.2 + +- [x] Retry kommand or multiple kommands throwing a [RecoverableError](https://github.com/apple/swift-evolution/blob/master/proposals/0112-nserror-bridging.md#new-protocols). + # Release 0.9.1 - [x] Removed DispatchWorkItem, now internally working with Operation. diff --git a/Kommander.podspec b/Kommander.podspec index 3aba5d5..71193cc 100755 --- a/Kommander.podspec +++ b/Kommander.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'Kommander' - s.version = '0.9.1' + s.version = '0.9.2' s.summary = 'A command pattern implementation written in Swift 4' s.homepage = 'https://github.com/intelygenz/Kommander-iOS' diff --git a/Kommander.xcodeproj/project.pbxproj b/Kommander.xcodeproj/project.pbxproj index 2525557..5350201 100755 --- a/Kommander.xcodeproj/project.pbxproj +++ b/Kommander.xcodeproj/project.pbxproj @@ -53,6 +53,9 @@ 81DBBB331E7691F400EF01D8 /* Major watchOS.app in Embed Watch Content */ = {isa = PBXBuildFile; fileRef = 81DBBB181E7691F300EF01D8 /* Major watchOS.app */; }; D56F57291F7BB864005B3692 /* Kommander.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 81DBBAD71E768DB300EF01D8 /* Kommander.framework */; }; D56F572A1F7BB864005B3692 /* Kommander.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 81DBBAD71E768DB300EF01D8 /* Kommander.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + D5D3583B1FA9E70500F1C79B /* KommandCancelledError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DE0DE341FA380CD001FAC71 /* KommandCancelledError.swift */; }; + D5D3583C1FA9E70500F1C79B /* KommandCancelledError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DE0DE341FA380CD001FAC71 /* KommandCancelledError.swift */; }; + D5D3583D1FA9E70600F1C79B /* KommandCancelledError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DE0DE341FA380CD001FAC71 /* KommandCancelledError.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -784,6 +787,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + D5D3583D1FA9E70600F1C79B /* KommandCancelledError.swift in Sources */, 819D15651E76AF7D00BB1F07 /* Kommander.swift in Sources */, 819D15691E76AF7D00BB1F07 /* CurrentDispatcher.swift in Sources */, 819D15661E76AF7D00BB1F07 /* Kommand.swift in Sources */, @@ -796,6 +800,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + D5D3583B1FA9E70500F1C79B /* KommandCancelledError.swift in Sources */, 81DBBB071E768EF000EF01D8 /* Kommander.swift in Sources */, 81DBBB011E768ED700EF01D8 /* CurrentDispatcher.swift in Sources */, 81DBBAFF1E768ED100EF01D8 /* Kommand.swift in Sources */, @@ -808,6 +813,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + D5D3583C1FA9E70500F1C79B /* KommandCancelledError.swift in Sources */, 81DBBB081E768EF100EF01D8 /* Kommander.swift in Sources */, 81DBBB021E768ED700EF01D8 /* CurrentDispatcher.swift in Sources */, 81DBBB001E768ED100EF01D8 /* Kommand.swift in Sources */, @@ -984,7 +990,7 @@ DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = 3VW789WSMP; DYLIB_COMPATIBILITY_VERSION = 0.9.0; - DYLIB_CURRENT_VERSION = 0.9.1; + DYLIB_CURRENT_VERSION = 0.9.2; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; @@ -1056,7 +1062,7 @@ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = 3VW789WSMP; DYLIB_COMPATIBILITY_VERSION = 0.9.0; - DYLIB_CURRENT_VERSION = 0.9.1; + DYLIB_CURRENT_VERSION = 0.9.2; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; diff --git a/KommanderTests/KommanderTests.swift b/KommanderTests/KommanderTests.swift index ceb756f..a419e28 100755 --- a/KommanderTests/KommanderTests.swift +++ b/KommanderTests/KommanderTests.swift @@ -178,6 +178,8 @@ class KommanderTests: XCTestCase { XCTAssertEqual(error.recoveryOptions, ["Retry the Kommand"]) let recoverySuccess = error.attemptRecovery(optionIndex: 0) XCTAssert(recoverySuccess) + let secondRecoverySuccess = error.attemptRecovery(optionIndex: 0) + XCTAssertFalse(secondRecoverySuccess) }) .execute() .cancel(true, after: .seconds(2)) diff --git a/README.md b/README.md index fc06a91..dd50d2b 100755 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ Inspired on the Java library [**Kommander**](https://github.com/Wokdsem/Kommande - [x] Make kommand or multiple kommands - [x] Execute kommand or multiple kommands - [x] Cancel kommand or multiple kommands +- [x] Retry kommand or multiple kommands - [x] Set kommand success block - [x] Set kommand error block - [x] Main thread dispatcher @@ -79,7 +80,7 @@ dependencies: [ ## Usage -#### Making, executing and cancelling Kommands: +#### Making, executing, cancelling and retrying Kommands: ```swift Kommander().makeKommand { @@ -119,6 +120,8 @@ let kommand = Kommander().makeKommand { () -> Any? in }).execute() kommand.cancel() + +kommand.retry() ``` #### Creating Kommanders: diff --git a/Source/Kommand.swift b/Source/Kommand.swift index cfcf522..e8e5c3a 100644 --- a/Source/Kommand.swift +++ b/Source/Kommand.swift @@ -83,7 +83,6 @@ open class Kommand { executor?.execute(after: delay, block: { self.execute() }) - return self } @@ -123,7 +122,6 @@ open class Kommand { executor?.execute(after: delay, block: { self.cancel(throwingError) }) - return self } @@ -134,7 +132,7 @@ open class Kommand { } self.deliverer?.execute { if throwingError { - self.errorBlock?(KommandCancelledError(kommand: self)) + self.errorBlock?(KommandCancelledError(self)) } } if let operation = operation, !operation.isFinished { @@ -149,7 +147,6 @@ open class Kommand { executor?.execute(after: delay, block: { self.retry() }) - return self } @@ -159,8 +156,7 @@ open class Kommand { return self } state = .ready - execute() - return self + return execute() } } diff --git a/Source/KommandCancelledError.swift b/Source/KommandCancelledError.swift index 43d6bd8..ac1e083 100644 --- a/Source/KommandCancelledError.swift +++ b/Source/KommandCancelledError.swift @@ -12,7 +12,7 @@ public struct KommandCancelledError: RecoverableError { private let kommand: Kommand - init(kommand: Kommand) { + init(_ kommand: Kommand) { self.kommand = kommand } @@ -21,6 +21,9 @@ public struct KommandCancelledError: RecoverableError { } public func attemptRecovery(optionIndex recoveryOptionIndex: Int) -> Bool { + guard kommand.state == .canceled else { + return false + } kommand.retry() return true }