Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/luoxiu/Schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
luoxiu committed Oct 6, 2020
2 parents 764b00a + 0f2b71d commit e388fca
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Sources/Schedule/RunLoopTask.swift
Expand Up @@ -58,12 +58,23 @@ private final class RunLoopTask: Task {
guard let task = task as? RunLoopTask, let timer = task.timer else { return }
timer.fireDate = Date()
}

#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)

timer = CFRunLoopTimerCreateWithHandler(kCFAllocatorDefault, Date.distantFuture.timeIntervalSinceReferenceDate, .greatestFiniteMagnitude, 0, 0, { [weak self] _ in
guard let self = self else { return }
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)
}

Expand Down

0 comments on commit e388fca

Please sign in to comment.