Merge pull request #66 from Austinpayne/fix/linux-build

fix error: cannot find 'CFRunLoopTimerCreateWithHandler' in scope
This commit is contained in:
Luo Xiu 2020-10-06 16:39:34 +08:00 committed by GitHub
commit 0f2b71d6f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 0 deletions

View File

@ -58,12 +58,23 @@ private final class RunLoopTask: Task {
guard let task = task as? RunLoopTask, let timer = task.timer else { return } guard let task = task as? RunLoopTask, let timer = task.timer else { return }
timer.fireDate = Date() timer.fireDate = Date()
} }
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
timer = CFRunLoopTimerCreateWithHandler(kCFAllocatorDefault, Date.distantFuture.timeIntervalSinceReferenceDate, .greatestFiniteMagnitude, 0, 0, { [weak self] _ in timer = CFRunLoopTimerCreateWithHandler(kCFAllocatorDefault, Date.distantFuture.timeIntervalSinceReferenceDate, .greatestFiniteMagnitude, 0, 0, { [weak self] _ in
guard let self = self else { return } guard let self = self else { return }
action(self) action(self)
}) })
#elseif os(Linux)
timer = Timer(fire: Date.distantFuture, interval: .greatestFiniteMagnitude, repeats: true) { [weak self] _ in
guard let self = self else { return }
action(self)
}
#endif
RunLoop.current.add(timer, forMode: mode) RunLoop.current.add(timer, forMode: mode)
} }