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