public struct EventLoopPromise<Value>

A promise to provide a result later.

This is the provider API for EventLoopFuture<Value>. If you want to return an unfulfilled EventLoopFuture<Value> – presumably because you are interfacing to some asynchronous service that will return a real result later, follow this pattern:

func someAsyncOperation(args) -> EventLoopFuture<ResultType> {
    let promise = eventLoop.makePromise(of: ResultType.self)
    someAsyncOperationWithACallback(args) { result -> Void in
        // when finished...
        // if error...
    return promise.futureResult

Note that the future result is returned before the async process has provided a value.

It’s actually not very common to use this directly. Usually, you really want one of the following:

  • If you have an EventLoopFuture and want to do something else after it completes, use .flatMap()
  • If you already have a value and need an EventLoopFuture<> object to plug into some other API, create an already-resolved object with eventLoop.makeSucceededFuture(result) or eventLoop.newFailedFuture(error:).

  • Note

    EventLoopPromise has reference semantics.