unwrap(orElse:)

Unwrap an EventLoopFuture where its type parameter is an Optional.

EventLoopFuture.swift:1848
@preconcurrency func unwrap<NewValue>(orElse callback: @escaping () -> NewValue) -> EventLoopFuture<NewValue> where Value == NewValue?

Parameters

callback

a closure that returns the value of the returned EventLoopFuture when then resolved future’s value is Optional.some().

Returns

an new EventLoopFuture with new type parameter NewValue and with the value returned by the closure passed in the callback parameter.

Unwraps a future returning a new EventLoopFuture with either: the value returned by the closure passed in the orElse parameter when the future resolved with value Optional.none, or the same value otherwise. For example:

var x = 2
promise.futureResult.unwrap(orElse: { x * 2 }).wait()