30 lines
544 B
Swift
30 lines
544 B
Swift
//
|
|
// SDLAsyncTimerStream.swift
|
|
// Tun
|
|
//
|
|
// Created by 安礼成 on 2026/2/3.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
class SDLAsyncTimerStream {
|
|
let timer: DispatchSourceTimer
|
|
|
|
init() {
|
|
self.timer = DispatchSource.makeTimerSource(queue: .global())
|
|
}
|
|
|
|
func start(_ cont: AsyncStream<Void>.Continuation) {
|
|
timer.schedule(deadline: .now(), repeating: .seconds(5))
|
|
timer.setEventHandler {
|
|
cont.yield()
|
|
}
|
|
timer.resume()
|
|
}
|
|
|
|
deinit {
|
|
self.timer.cancel()
|
|
}
|
|
|
|
}
|