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

Commit

Permalink
Release 0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Rupérez committed Mar 24, 2017
1 parent 28b5f75 commit 3a85b1b
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 14 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Release 0.6.0

- [x] Execute and cancel after delay
- [x] Kommand cancellation fix

# Release 0.5.0

- [x] Concurrent/Sequential Kommands execution refactor
Expand Down
2 changes: 1 addition & 1 deletion Kommander.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Kommander'
s.version = '0.5.0'
s.version = '0.6.0'
s.summary = 'A command pattern implementation written in Swift 3'

s.homepage = 'https://github.com/intelygenz/Kommander-iOS'
Expand Down
8 changes: 4 additions & 4 deletions Kommander.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -970,8 +970,8 @@
CURRENT_PROJECT_VERSION = "$(DYLIB_CURRENT_VERSION)";
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = 3VW789WSMP;
DYLIB_COMPATIBILITY_VERSION = 0.5.0;
DYLIB_CURRENT_VERSION = 0.5.0;
DYLIB_COMPATIBILITY_VERSION = 0.6.0;
DYLIB_CURRENT_VERSION = 0.6.0;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
Expand Down Expand Up @@ -1035,8 +1035,8 @@
CURRENT_PROJECT_VERSION = "$(DYLIB_CURRENT_VERSION)";
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = 3VW789WSMP;
DYLIB_COMPATIBILITY_VERSION = 0.5.0;
DYLIB_CURRENT_VERSION = 0.5.0;
DYLIB_COMPATIBILITY_VERSION = 0.6.0;
DYLIB_CURRENT_VERSION = 0.6.0;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
Expand Down
38 changes: 34 additions & 4 deletions Source/Dispatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,35 @@ open class Dispatcher {
/// Dispatcher queue priority
private final var priority = Priority.operation

/// Main queue dispatcher
open static var main: Dispatcher { return MainDispatcher() }
/// Current queue dispatcher
open static var current: Dispatcher { return CurrentDispatcher() }
/// Dispatcher with default quality of service
open static var `default`: Dispatcher { return Dispatcher() }
/// Dispatcher with user interactive quality of service
open static var userInteractive: Dispatcher { return Dispatcher(name: nil, qos: .userInteractive) }
/// Dispatcher with user initiated quality of service
open static var userInitiated: Dispatcher { return Dispatcher(name: nil, qos: .userInitiated) }
/// Dispatcher with utility quality of service
open static var utility: Dispatcher { return Dispatcher(name: nil, qos: .utility) }
/// Dispatcher with background quality of service
open static var background: Dispatcher { return Dispatcher(name: nil, qos: .background) }

/// Dispatcher instance with default OperationQueue
public convenience init() {
self.init(name: nil, qos: nil, maxConcurrentOperationCount: OperationQueue.defaultMaxConcurrentOperationCount)
self.init(name: nil, qos: .default)
}

/// Dispatcher instance with custom OperationQueue
public init(name: String?, qos: QualityOfService?, maxConcurrentOperationCount: Int) {
public init(name: String?, qos: QualityOfService?, maxConcurrentOperationCount: Int? = nil) {
operationQueue.name = name ?? UUID().uuidString
operationQueue.qualityOfService = qos ?? .default
operationQueue.maxConcurrentOperationCount = maxConcurrentOperationCount
operationQueue.maxConcurrentOperationCount = maxConcurrentOperationCount ?? OperationQueue.defaultMaxConcurrentOperationCount
}

/// Dispatcher instance with custom DispatchQueue
public init(label: String?, qos: DispatchQoS?, attributes: DispatchQueue.Attributes?, autoreleaseFrequency: DispatchQueue.AutoreleaseFrequency?, target: DispatchQueue?) {
public init(label: String?, qos: DispatchQoS?, attributes: DispatchQueue.Attributes? = nil, autoreleaseFrequency: DispatchQueue.AutoreleaseFrequency? = nil, target: DispatchQueue? = nil) {
dispatchQueue = DispatchQueue(label: label ?? UUID().uuidString, qos: qos ?? .default, attributes: attributes ?? .concurrent, autoreleaseFrequency: autoreleaseFrequency ?? .inherit, target: target)
priority = .dispatch
}
Expand Down Expand Up @@ -81,6 +96,21 @@ open class Dispatcher {
return operations
}

/// Execute block in DispatchQueue after delay
open func execute(after delay: TimeInterval, block: @escaping () -> Void) {
dispatchQueue.asyncAfter(deadline: .now() + delay, execute: block)
}

/// Execute block in DispatchQueue using custom DispatchWorkItem instance after delay
open func execute(after delay: TimeInterval, qos: DispatchQoS?, flags: DispatchWorkItemFlags?, block: @escaping @convention(block) () -> ()) {
dispatchQueue.asyncAfter(deadline: .now() + delay, qos: qos ?? .default, flags: flags ?? .assignCurrentContext, execute: block)
}

/// Execute DispatchWorkItem instance in DispatchQueue after delay
open func execute(after delay: TimeInterval, work: DispatchWorkItem) {
dispatchQueue.asyncAfter(deadline: .now() + delay, execute: work)
}

/// Execute block in DispatchQueue using custom DispatchWorkItem instance
open func execute(qos: DispatchQoS?, flags: DispatchWorkItemFlags?, block: @escaping @convention(block) () -> ()) -> DispatchWorkItem {
let work = DispatchWorkItem(qos: qos ?? .default, flags: flags ?? .assignCurrentContext, block: block)
Expand Down
4 changes: 2 additions & 2 deletions Source/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.5.0</string>
<string>0.6.0</string>
<key>CFBundleVersion</key>
<string>0.5.0</string>
<string>0.6.0</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
Expand Down
18 changes: 17 additions & 1 deletion Source/Kommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ open class Kommand<Result> {
return self
}

/// Execute Kommand<Result> after delay
open func execute(after delay: TimeInterval) -> Self {
executor?.execute(after: delay, block: {
_ = self.execute()
})

return self
}

/// Execute Kommand<Result>
open func execute() -> Self {
guard state == .ready else {
Expand Down Expand Up @@ -118,6 +127,13 @@ open class Kommand<Result> {
return self
}

/// Cancel Kommand<Result> after delay
open func cancel(_ throwingError: Bool = false, after delay: TimeInterval) {
executor?.execute(after: delay, block: {
_ = self.cancel(throwingError)
})
}

/// Cancel Kommand<Result>
open func cancel(_ throwingError: Bool = false) {
guard state != .canceled else {
Expand All @@ -130,7 +146,7 @@ open class Kommand<Result> {
self.errorBlock = nil
self.deliverer = nil
}
if let operation = operation, operation.isExecuting {
if let operation = operation, !operation.isFinished {
operation.cancel()
}
else if let work = work, !work.isCancelled {
Expand Down
29 changes: 29 additions & 0 deletions Source/Kommander.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@ open class Kommander {
/// Executor
private final let executor: Dispatcher

/// Kommander instance with CurrentDispatcher deliverer and MainDispatcher executor
open static var main: Kommander { return Kommander(executor: Dispatcher.main) }
/// Kommander instance with CurrentDispatcher deliverer and CurrentDispatcher executor
open static var current: Kommander { return Kommander(executor: Dispatcher.current) }
/// Kommander instance with CurrentDispatcher deliverer and Dispatcher executor with default quality of service
open static var `default`: Kommander { return Kommander(executor: Dispatcher.default) }
/// Kommander instance with CurrentDispatcher deliverer and Dispatcher executor with user interactive quality of service
open static var userInteractive: Kommander { return Kommander(executor: Dispatcher.userInteractive) }
/// Kommander instance with CurrentDispatcher deliverer and Dispatcher executor with user initiated quality of service
open static var userInitiated: Kommander { return Kommander(executor: Dispatcher.userInitiated) }
/// Kommander instance with CurrentDispatcher deliverer and Dispatcher executor with utility quality of service
open static var utility: Kommander { return Kommander(executor: Dispatcher.utility) }
/// Kommander instance with CurrentDispatcher deliverer and Dispatcher executor with background quality of service
open static var background: Kommander { return Kommander(executor: Dispatcher.background) }

/// Kommander instance with CurrentDispatcher deliverer and default Dispatcher executor
public convenience init() {
self.init(deliverer: nil, executor: nil)
Expand Down Expand Up @@ -73,6 +88,13 @@ open class Kommander {
return kommands
}

/// Execute [Kommand<Result>] instances collection concurrently or sequentially after delay
open func execute<Result>(_ kommands: [Kommand<Result>], concurrent: Bool = true, waitUntilFinished: Bool = false, after delay: TimeInterval) {
executor.execute(after: delay) {
self.execute(kommands, concurrent: concurrent, waitUntilFinished: waitUntilFinished)
}
}

/// Execute [Kommand<Result>] instances collection concurrently or sequentially
open func execute<Result>(_ kommands: [Kommand<Result>], concurrent: Bool = true, waitUntilFinished: Bool = false) {
let blocks = kommands.map { kommand -> () -> Void in
Expand Down Expand Up @@ -113,6 +135,13 @@ open class Kommander {
}
}

/// Cancel [Kommand<Result>] instances collection after delay
open func cancel<Result>(_ kommands: [Kommand<Result>], throwingError: Bool = false, after delay: TimeInterval) {
executor.execute(after: delay) {
self.cancel(kommands, throwingError: throwingError)
}
}

/// Cancel [Kommand<Result>] instances collection
open func cancel<Result>(_ kommands: [Kommand<Result>], throwingError: Bool = false) {
for kommand in kommands {
Expand Down
4 changes: 2 additions & 2 deletions Source/MainDispatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ open class MainDispatcher: Dispatcher {

/// Dispatcher instance with main OperationQueue
public init() {
super.init(name: nil, qos: nil, maxConcurrentOperationCount: OperationQueue.defaultMaxConcurrentOperationCount)
super.init(name: nil, qos: nil)
operationQueue = OperationQueue.main
dispatchQueue = DispatchQueue.main
}

/// - Warning: You can't use this initializer!
private override convenience init(name: String?, qos: QualityOfService?, maxConcurrentOperationCount: Int) {
private override convenience init(name: String?, qos: QualityOfService?, maxConcurrentOperationCount: Int? = nil) {
self.init()
assertionFailure("You can't use this initializer for a \(String(describing: type(of: self))).")
}
Expand Down

0 comments on commit 3a85b1b

Please sign in to comment.