Skip to content

Instance Method

guard(_:else:)

Guards that the future’s value satisfies the callback’s condition or fails with the given error.
func `guard`(_ callback: @escaping (Value) -> Bool, else error: @autoclosure @escaping () -> any Error) -> EventLoopFuture<Value>

Parameters

callback

Callback that asynchronously executes a condition.

error

The error to fail with if condition isn’t met.

Return Value

A future containing the original future’s result.

Discussion

Example usage:

future.guard({ $0.userID == user.id }, else: AccessError.unauthorized)

See Also

EventLoopFuture