Simplify async scheduler
This commit is contained in:
@ -1,34 +1,10 @@
|
||||
import Foundation
|
||||
import Vapor
|
||||
import NIOCore
|
||||
import Clairvoyant
|
||||
|
||||
final class EventLoopScheduler {
|
||||
extension MultiThreadedEventLoopGroup: AsyncScheduler {
|
||||
|
||||
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
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension EventLoopScheduler: AsyncScheduler {
|
||||
|
||||
func schedule(asyncJob: @escaping @Sendable () async throws -> Void) {
|
||||
_ = backgroundGroup.any().makeFutureWithTask(asyncJob)
|
||||
public func schedule(asyncJob: @escaping @Sendable () async throws -> Void) {
|
||||
_ = any().makeFutureWithTask(asyncJob)
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ var deviceManager: DeviceManager!
|
||||
|
||||
private var provider: VaporMetricProvider!
|
||||
|
||||
private var asyncScheduler = EventLoopScheduler()
|
||||
private var asyncScheduler: AsyncScheduler = MultiThreadedEventLoopGroup(numberOfThreads: 2)
|
||||
|
||||
enum ServerError: Error {
|
||||
case invalidAuthenticationFileContent
|
||||
|
Reference in New Issue
Block a user