-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from orchetect/dev
Dev merge
- Loading branch information
Showing
35 changed files
with
321 additions
and
3,259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
Sources/OTCore/Extensions/Dispatch/DispatchTimeInterval.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// | ||
// DispatchTimeInterval.swift | ||
// OTCore • https://github.com/orchetect/OTCore | ||
// | ||
|
||
#if canImport(Dispatch) | ||
|
||
import Dispatch | ||
|
||
extension DispatchTimeInterval { | ||
|
||
/// **OTCore:** | ||
/// Return the interval as `Int` seconds. | ||
public var microseconds: Int { | ||
|
||
switch self { | ||
case .seconds(let val): | ||
return val * 1_000_000 | ||
|
||
case .milliseconds(let val): // ms | ||
return val * 1_000 | ||
|
||
case .microseconds(let val): // µs | ||
return val | ||
|
||
case .nanoseconds(let val): // ns | ||
return val / 1_000 | ||
|
||
case .never: | ||
assertionFailure("Cannot convert 'never' to microseconds.") | ||
return 0 | ||
|
||
@unknown default: | ||
assertionFailure("Unhandled DispatchTimeInterval case when attempting to convert to microseconds.") | ||
return 0 | ||
|
||
} | ||
|
||
} | ||
|
||
} | ||
|
||
/// **OTCore:** | ||
/// Convenience to convert a `DispatchTimeInterval` to microseconds and run `usleep()`. | ||
@_disfavoredOverload | ||
public func sleep(_ dispatchTimeInterval: DispatchTimeInterval) { | ||
|
||
let ms = dispatchTimeInterval.microseconds | ||
guard ms > 0 else { return } | ||
usleep(UInt32(ms)) | ||
|
||
} | ||
|
||
#endif |
21 changes: 21 additions & 0 deletions
21
Sources/OTCore/Extensions/Foundation/Darwin and Foundation.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// Darwin and Foundation.swift | ||
// OTCore • https://github.com/orchetect/OTCore | ||
// | ||
|
||
#if canImport(Foundation) | ||
|
||
import Foundation | ||
|
||
/// **OTCore:** | ||
/// Convenience to convert a `TimeInterval` to microseconds and run `usleep()`. | ||
@_disfavoredOverload | ||
public func sleep(_ timeInterval: TimeInterval) { | ||
|
||
let ms = timeInterval * 1_000_000 | ||
guard ms > 0.0 else { return } | ||
usleep(UInt32(ms)) | ||
|
||
} | ||
|
||
#endif |
58 changes: 57 additions & 1 deletion
58
Sources/OTCore/Extensions/Foundation/Dispatch and Foundation.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,108 @@ | ||
// | ||
// File.swift | ||
// Dispatch and Foundation.swift | ||
// OTCore • https://github.com/orchetect/OTCore | ||
// | ||
|
||
#if canImport(Foundation) | ||
|
||
import Foundation // imports Dispatch | ||
|
||
// MARK: - QualityOfService / QoSClass | ||
|
||
extension QualityOfService { | ||
|
||
/// Returns the Dispatch framework `DispatchQoS.QoSClass` equivalent. | ||
public var dispatchQoSClass: DispatchQoS.QoSClass { | ||
|
||
switch self { | ||
case .userInteractive: | ||
return .userInteractive | ||
|
||
case .userInitiated: | ||
return .userInitiated | ||
|
||
case .utility: | ||
return .utility | ||
|
||
case .background: | ||
return .background | ||
|
||
case .default: | ||
return .default | ||
|
||
@unknown default: | ||
return .default | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
extension DispatchQoS.QoSClass { | ||
|
||
/// Returns the Foundation framework `QualityOfService` equivalent. | ||
public var qualityOfService: QualityOfService { | ||
|
||
switch self { | ||
case .userInteractive: | ||
return .userInteractive | ||
|
||
case .userInitiated: | ||
return .userInitiated | ||
|
||
case .utility: | ||
return .utility | ||
|
||
case .background: | ||
return .background | ||
|
||
case .default: | ||
return .default | ||
|
||
case .unspecified: | ||
return .default | ||
|
||
@unknown default: | ||
return .default | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
// MARK: - DispatchTimeInterval | ||
|
||
extension DispatchTimeInterval { | ||
|
||
/// **OTCore:** | ||
/// Return the interval as a `TimeInterval` (floating-point seconds). | ||
public var timeInterval: TimeInterval? { | ||
|
||
switch self { | ||
case .seconds(let val): | ||
return TimeInterval(val) | ||
|
||
case .milliseconds(let val): // ms | ||
return TimeInterval(val) / 1_000 | ||
|
||
case .microseconds(let val): // µs | ||
return TimeInterval(val) / 1_000_000 | ||
|
||
case .nanoseconds(let val): // ns | ||
return TimeInterval(val) / 1_000_000_000 | ||
|
||
case .never: | ||
//assertionFailure("Cannot convert 'never' to TimeInterval.") | ||
return nil | ||
|
||
@unknown default: | ||
assertionFailure("Unhandled DispatchTimeInterval case when attempting to convert to TimeInterval.") | ||
return nil | ||
|
||
} | ||
|
||
} | ||
|
||
} | ||
|
||
#endif |
33 changes: 0 additions & 33 deletions
33
Sources/OTCore/Threading/Operation Common/AtomicVariableAccess.swift
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.