Sesame-Server/Sources/App/EventLoopScheduler.swift

35 lines
696 B
Swift
Raw Normal View History

2023-10-01 19:26:31 +02:00
import Foundation
import Vapor
import NIOCore
2023-10-24 19:09:49 +02:00
import Clairvoyant
2023-10-01 19:26:31 +02:00
final class EventLoopScheduler {
private let backgroundGroup: EventLoopGroup
init() {
backgroundGroup = MultiThreadedEventLoopGroup(numberOfThreads: 2)
}
func next() -> EventLoop {
backgroundGroup.next()
}
func provider() -> NIOEventLoopGroupProvider {
return .shared(backgroundGroup)
}
func shutdown() {
backgroundGroup.shutdownGracefully { _ in
}
}
}
2023-10-24 19:09:49 +02:00
extension EventLoopScheduler: AsyncScheduler {
2023-10-01 19:26:31 +02:00
func schedule(asyncJob: @escaping @Sendable () async throws -> Void) {
_ = backgroundGroup.any().makeFutureWithTask(asyncJob)
}
}