async overload for `Command.run(using context: CommandContext, signature: Signature)`
finestructure opened this issue · 0 comments
finestructure commented
In the context of converting a code base using Vapor commands for batch jobs to Swift 5.5's async/await, the issue arose that run
does not have an async overload. This poses the following problem when converting
fun run(using context: CommandContext, signature: Signature) throws {
try f.wait()
}
where f
is func f() → EventLoopFuture<Void>
.
A workaround is to use
func run(using context: CommandContext, signature: Signature) throws {
let promise = context.application.eventLoopGroup.next()
.makePromise(of: Void.self)
promise.completeWithAsync {
try await f()
}
try promise.futureResult.wait()
}
but it would be nice if this wrapper (or simply handling via @main
, if possible, or some other solution) existed upstream such that one could simply write
func run(using context: CommandContext, signature: Signature) async throws {
try await f()
}