From a246f3d30b0a01ec4ee79f8f3e5771928f596055 Mon Sep 17 00:00:00 2001 From: "Dr. Michael Lauer" Date: Thu, 23 Mar 2023 07:57:54 +0000 Subject: [PATCH] Timer+Oneshot: Repair Linux build. Yet another Foundation API mismatch: https://github.com/apple/swift-corelibs-foundation/issues/4724 --- .../Extensions/Timer/Timer+Oneshot.swift | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Sources/CornucopiaCore/Extensions/Timer/Timer+Oneshot.swift b/Sources/CornucopiaCore/Extensions/Timer/Timer+Oneshot.swift index 8fdec2e..d4de2b2 100644 --- a/Sources/CornucopiaCore/Extensions/Timer/Timer+Oneshot.swift +++ b/Sources/CornucopiaCore/Extensions/Timer/Timer+Oneshot.swift @@ -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 + } } }