Simplify scheduler
This commit is contained in:
parent
e62ccb9241
commit
a08dc4f175
@ -1,34 +1,10 @@
|
||||
import Foundation
|
||||
import Clairvoyant
|
||||
import Vapor
|
||||
import NIOCore
|
||||
import Clairvoyant
|
||||
|
||||
final class EventLoopScheduler {
|
||||
|
||||
private let backgroundGroup: EventLoopGroup
|
||||
|
||||
init(numberOfThreads: Int = 2) {
|
||||
backgroundGroup = MultiThreadedEventLoopGroup(numberOfThreads: numberOfThreads)
|
||||
}
|
||||
|
||||
func next() -> EventLoop {
|
||||
backgroundGroup.next()
|
||||
}
|
||||
|
||||
func provider() -> NIOEventLoopGroupProvider {
|
||||
return .shared(backgroundGroup)
|
||||
}
|
||||
|
||||
func shutdown() {
|
||||
backgroundGroup.shutdownGracefully { _ in
|
||||
extension MultiThreadedEventLoopGroup: AsyncScheduler {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ var server: SQLiteDatabase!
|
||||
|
||||
private var provider: VaporMetricProvider! = nil
|
||||
private var status: Metric<ServerStatus>!
|
||||
private let scheduler = EventLoopScheduler()
|
||||
private let scheduler = MultiThreadedEventLoopGroup(numberOfThreads: 2)
|
||||
private var configurationError: Error? = nil
|
||||
|
||||
func configure(_ app: Application) async throws {
|
||||
@ -77,6 +77,7 @@ func configure(_ app: Application) async throws {
|
||||
func shutdown() {
|
||||
scheduler.schedule {
|
||||
await server.disconnectAllSockets()
|
||||
try await scheduler.shutdownGracefully()
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user