Which event loop should I use in Swift NIO?

Viewed 169

The example in the docs shows an existing reference to the EventLoop for use with creating a future.

func getNetworkData(args) -> EventLoopFuture<NetworkResponse> {
    let promise = eventLoop.makePromise(of: NetworkResponse.self)
    queue.async {
        . . . do some work . . .
        promise.succeed(response)
        . . . if it fails, instead . . .
        promise.fail(error)
    }
    return promise.futureResult
}

In my case, I don't have access to the current EventLoop. Is there an easy way to get access to it?

Alternatively, I have access to an EventLoopGroup and I can use services.lambda.client.eventLoopGroup.next() to get an EventLoop. Does that just create extra overhead though? Should I be looking for an existing EventLoop?

0 Answers
Related