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

Commit

Permalink
Merge pull request #8 from intelygenz/feature/#7-many-initializers-ma…
Browse files Browse the repository at this point in the history
…ny-parameters, this will resolve #7
  • Loading branch information
alexruperez authored Oct 26, 2017
2 parents ae5c158 + 78c9459 commit a656c76
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 25 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Release 0.8.1

- [x] Deprecated some DispatchQueue methods and initializers.

# Release 0.8.0

- [x] Swift 4.0
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.8.0'
s.version = '0.8.1'
s.summary = 'A command pattern implementation written in Swift 4'

s.homepage = 'https://github.com/intelygenz/Kommander-iOS'
Expand Down
4 changes: 2 additions & 2 deletions Kommander.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = 3VW789WSMP;
DYLIB_COMPATIBILITY_VERSION = 0.8.0;
DYLIB_CURRENT_VERSION = 0.8.0;
DYLIB_CURRENT_VERSION = 0.8.1;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
Expand Down Expand Up @@ -1052,7 +1052,7 @@
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = 3VW789WSMP;
DYLIB_COMPATIBILITY_VERSION = 0.8.0;
DYLIB_CURRENT_VERSION = 0.8.0;
DYLIB_CURRENT_VERSION = 0.8.1;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ Inspired on the Java library [**Kommander**](https://github.com/Wokdsem/Kommande
- [x] Main thread dispatcher
- [x] Current thread dispatcher
- [x] Custom OperationQueue dispatcher
- [x] Custom DispatchQueue dispatcher
- [x] Execute single or multiple Operation
- [x] Execute sequential or concurrent blocks
- [x] Execute DispatchWorkItem
Expand Down
25 changes: 6 additions & 19 deletions Source/Dispatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,13 @@

import Foundation

/// Queue priority
private enum Priority {
/// Operation queue priority
case operation
/// Dispatch queue priority
case dispatch
}

/// Dispatcher
open class Dispatcher {

/// Dispatcher operation queue
final var operationQueue = OperationQueue()
/// Dispatcher dispatch queue
final var dispatchQueue = DispatchQueue(label: UUID().uuidString)
/// Dispatcher queue priority
private final var priority = Priority.operation

/// Main queue dispatcher
open static var main: Dispatcher { return MainDispatcher() }
Expand Down Expand Up @@ -54,9 +44,9 @@ open class Dispatcher {
}

/// Dispatcher instance with custom DispatchQueue
@available(*, deprecated, message: "This will be removed in Kommander 0.9. Use `Dispatcher.init(name:qos:maxConcurrentOperationCount:)` instead.")
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
}

/// Execute Operation instance in OperationQueue
Expand All @@ -71,14 +61,9 @@ open class Dispatcher {

/// Execute block in priority queue
@discardableResult open func execute(_ block: @escaping () -> Void) -> Any {
if priority == .dispatch {
return execute(qos: nil, flags: nil, block: block)
}
else {
let blockOperation = BlockOperation(block: block)
execute(blockOperation)
return blockOperation
}
let blockOperation = BlockOperation(block: block)
execute(blockOperation)
return blockOperation
}

/// Execute [block] collection in priority queue (if possible) concurrently or sequentially
Expand All @@ -105,6 +90,7 @@ open class Dispatcher {
}

/// Execute block in DispatchQueue using custom DispatchWorkItem instance after delay
@available(*, deprecated, message: "This will be removed in Kommander 0.9. Use `execute(delay:work:)` instead.")
open func execute(after delay: DispatchTimeInterval, qos: DispatchQoS?, flags: DispatchWorkItemFlags?, block: @escaping @convention(block) () -> ()) {
guard delay != .never else {
return
Expand All @@ -122,6 +108,7 @@ open class Dispatcher {
}

/// Execute block in DispatchQueue using custom DispatchWorkItem instance
@available(*, deprecated, message: "This will be removed in Kommander 0.9. Use `execute(work:)` instead.")
@discardableResult open func execute(qos: DispatchQoS?, flags: DispatchWorkItemFlags?, block: @escaping @convention(block) () -> ()) -> DispatchWorkItem {
let work = DispatchWorkItem(qos: qos ?? .default, flags: flags ?? .assignCurrentContext, block: block)
execute(work)
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.8.0</string>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>0.8.0</string>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
Expand Down
3 changes: 3 additions & 0 deletions Source/Kommander.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ open class Kommander {
}

/// Kommander instance with your deliverer and default Dispatcher executor
@available(*, deprecated, message: "This will be removed in Kommander 0.9. Use `Kommander.init(deliverer:executor:)` instead.")
public convenience init(deliverer: Dispatcher) {
self.init(deliverer: deliverer, executor: nil)
}
Expand All @@ -58,6 +59,7 @@ open class Kommander {
}

/// Kommander instance with CurrentDispatcher deliverer and custom DispatchQueue executor
@available(*, deprecated, message: "This will be removed in Kommander 0.9. Use `Kommander.init(name:qos:maxConcurrentOperationCount:)` instead.")
public convenience init(name: String?, qos: DispatchQoS?, attributes: DispatchQueue.Attributes?, autoreleaseFrequency: DispatchQueue.AutoreleaseFrequency?, target: DispatchQueue?) {
self.init(deliverer: nil, name: name, qos: qos, attributes: attributes, autoreleaseFrequency: autoreleaseFrequency, target: target)
}
Expand All @@ -69,6 +71,7 @@ open class Kommander {
}

/// Kommander instance with your deliverer and custom DispatchQueue executor
@available(*, deprecated, message: "This will be removed in Kommander 0.9. Use `Kommander.init(deliverer:name:qos:maxConcurrentOperationCount:)` instead.")
public init(deliverer: Dispatcher?, name: String?, qos: DispatchQoS?, attributes: DispatchQueue.Attributes?, autoreleaseFrequency: DispatchQueue.AutoreleaseFrequency?, target: DispatchQueue?) {
self.deliverer = deliverer ?? CurrentDispatcher()
executor = Dispatcher(label: name, qos: qos, attributes: attributes, autoreleaseFrequency: autoreleaseFrequency, target: target)
Expand Down
1 change: 1 addition & 0 deletions Source/MainDispatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ open class MainDispatcher: Dispatcher {
}

/// - Warning: You can't use this initializer!
@available(*, deprecated, message: "This will be removed in Kommander 0.9. Use `MainDispatcher.init()` instead.")
private override convenience init(label: String?, qos: DispatchQoS?, attributes: DispatchQueue.Attributes?, autoreleaseFrequency: DispatchQueue.AutoreleaseFrequency?, target: DispatchQueue?) {
self.init()
assertionFailure("You can't use this initializer for a \(String(describing: type(of: self))).")
Expand Down

0 comments on commit a656c76

Please sign in to comment.