This commit is contained in:
xq.jin 2020-10-06 16:41:24 +08:00
commit e388fcab1d
1 changed files with 11 additions and 0 deletions

View File

@ -59,11 +59,22 @@ private final class RunLoopTask: Task {
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)
} }