Simplify async scheduler
This commit is contained in:
parent
39766467e6
commit
b8c7256b9d
@ -8,8 +8,8 @@ let package = Package(
|
|||||||
],
|
],
|
||||||
dependencies: [
|
dependencies: [
|
||||||
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"),
|
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"),
|
||||||
.package(url: "https://github.com/christophhagen/Clairvoyant", from: "0.9.0"),
|
.package(url: "https://github.com/christophhagen/Clairvoyant", from: "0.13.0"),
|
||||||
.package(url: "https://github.com/christophhagen/ClairvoyantVapor", from: "0.2.0"),
|
.package(url: "https://github.com/christophhagen/ClairvoyantVapor", from: "0.5.0"),
|
||||||
.package(url: "https://github.com/christophhagen/ClairvoyantBinaryCodable", from: "0.3.1"),
|
.package(url: "https://github.com/christophhagen/ClairvoyantBinaryCodable", from: "0.3.1"),
|
||||||
],
|
],
|
||||||
targets: [
|
targets: [
|
||||||
|
@ -1,34 +1,10 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import Vapor
|
import Vapor
|
||||||
import NIOCore
|
|
||||||
import Clairvoyant
|
import Clairvoyant
|
||||||
|
|
||||||
final class EventLoopScheduler {
|
extension MultiThreadedEventLoopGroup: AsyncScheduler {
|
||||||
|
|
||||||
private let backgroundGroup: EventLoopGroup
|
public func schedule(asyncJob: @escaping @Sendable () async throws -> Void) {
|
||||||
|
_ = any().makeFutureWithTask(asyncJob)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ var deviceManager: DeviceManager!
|
|||||||
|
|
||||||
private var provider: VaporMetricProvider!
|
private var provider: VaporMetricProvider!
|
||||||
|
|
||||||
private var asyncScheduler = EventLoopScheduler()
|
private var asyncScheduler: AsyncScheduler = MultiThreadedEventLoopGroup(numberOfThreads: 2)
|
||||||
|
|
||||||
enum ServerError: Error {
|
enum ServerError: Error {
|
||||||
case invalidAuthenticationFileContent
|
case invalidAuthenticationFileContent
|
||||||
|
Loading…
Reference in New Issue
Block a user