import Foundation import Clairvoyant import Vapor import NIOCore 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 EventLoopScheduler: AsyncScheduler { func schedule(asyncJob: @escaping @Sendable () async throws -> Void) { _ = backgroundGroup.any().makeFutureWithTask(asyncJob) } }