Skip to content

Commit

Permalink
Merge pull request #34 from orchetect/dev
Browse files Browse the repository at this point in the history
Dev merge
  • Loading branch information
orchetect authored Feb 14, 2022
2 parents 84f0ece + f1e6724 commit 4ffe5e6
Show file tree
Hide file tree
Showing 35 changed files with 321 additions and 3,259 deletions.
3 changes: 2 additions & 1 deletion .swiftpm/xcode/xcshareddata/xcschemes/OTCore-CI.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
codeCoverageEnabled = "YES">
<Testables>
<TestableReference
skipped = "NO">
skipped = "NO"
testExecutionOrdering = "random">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "OTCoreTests"
Expand Down
17 changes: 12 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

Expand All @@ -22,26 +21,34 @@ let package = Package(
],

dependencies: [
.package(url: "https://github.com/orchetect/OTAtomics", from: "1.0.0"),

// testing-only dependency
.package(url: "https://github.com/orchetect/SegmentedProgress", from: "1.0.1"),
.package(url: "https://github.com/orchetect/SegmentedProgress", from: "1.0.1")
],

targets: [
.target(
name: "OTCore",
dependencies: []),
dependencies: ["OTAtomics"]),

.testTarget(
name: "OTCoreTests",
dependencies: ["OTCore", "SegmentedProgress"])
dependencies: ["OTCore", "OTAtomics", "SegmentedProgress"])
]

)

func addShouldTestFlag() {
var swiftSettings = package.targets
.first(where: { $0.name == "OTCoreTests" })?
.swiftSettings ?? []

swiftSettings.append(.define("shouldTestCurrentPlatform"))

package.targets
.first(where: { $0.name == "OTCoreTests" })?
.swiftSettings = [.define("shouldTestCurrentPlatform")]
.swiftSettings = swiftSettings
}

// Swift version in Xcode 12.5.1 which introduced watchOS testing
Expand Down
101 changes: 0 additions & 101 deletions Sources/OTCore/Atomics/Atomic.swift

This file was deleted.

54 changes: 54 additions & 0 deletions Sources/OTCore/Extensions/Dispatch/DispatchTimeInterval.swift
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 Sources/OTCore/Extensions/Foundation/Darwin and Foundation.swift
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
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

This file was deleted.

Loading

0 comments on commit 4ffe5e6

Please sign in to comment.