Skip to content

Commit a246f3d

Browse files
committed
Timer+Oneshot: Repair Linux build.
Yet another Foundation API mismatch: https://github.com/apple/swift-corelibs-foundation/issues/4724
1 parent d924738 commit a246f3d

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Sources/CornucopiaCore/Extensions/Timer/Timer+Oneshot.swift

+9-4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@ extension Timer {
99
/// Returns a ``Timer``, scheduled to fire exactly once after the specified `interval`.
1010
/// If you're not supplying a ``RunLoop`` argument, we're using the one for the current ``Thread``.
1111
public static func CC_oneShot(interval: DispatchTimeInterval, runloop: RunLoop = .current, mode: RunLoop.Mode = .common, block: @escaping @Sendable (Timer) -> Void) -> Timer? {
12-
guard interval != .never else { return nil }
13-
let timer = Timer(fire: Date() + interval.CC_timeInterval, interval: 0, repeats: false, block: block)
14-
runloop.add(timer, forMode: mode)
15-
return timer
12+
//This does not work on Linux due to https://github.com/apple/swift-corelibs-foundation/issues/4724
13+
//guard interval != .never else { return nil }
14+
switch interval {
15+
case .never: return nil
16+
default:
17+
let timer = Timer(fire: Date() + interval.CC_timeInterval, interval: 0, repeats: false, block: block)
18+
runloop.add(timer, forMode: mode)
19+
return timer
20+
}
1621
}
1722
}

0 commit comments

Comments
 (0)