Skip to content

Commit

Permalink
Timer+Oneshot: Repair Linux build.
Browse files Browse the repository at this point in the history
  • Loading branch information
mickeyl committed Mar 23, 2023
1 parent d924738 commit a246f3d
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions Sources/CornucopiaCore/Extensions/Timer/Timer+Oneshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ extension Timer {
/// Returns a ``Timer``, scheduled to fire exactly once after the specified `interval`.
/// If you're not supplying a ``RunLoop`` argument, we're using the one for the current ``Thread``.
public static func CC_oneShot(interval: DispatchTimeInterval, runloop: RunLoop = .current, mode: RunLoop.Mode = .common, block: @escaping @Sendable (Timer) -> Void) -> Timer? {
guard interval != .never else { return nil }
let timer = Timer(fire: Date() + interval.CC_timeInterval, interval: 0, repeats: false, block: block)
runloop.add(timer, forMode: mode)
return timer
//This does not work on Linux due to https://github.com/apple/swift-corelibs-foundation/issues/4724
//guard interval != .never else { return nil }
switch interval {
case .never: return nil
default:
let timer = Timer(fire: Date() + interval.CC_timeInterval, interval: 0, repeats: false, block: block)
runloop.add(timer, forMode: mode)
return timer
}
}
}

0 comments on commit a246f3d

Please sign in to comment.