FutureToResultX<T> extension

Bridges a regular Future<T> (which signals failure by throwing) into a Future<Result<T>> without writing Result.tryRunAsync(() => future) at every call site.

Named asResult (rather than toResult) to avoid colliding with the transport-specific .toResult() methods provided by the retrofit / chopper integration barrels.

on

Methods

asResult({Failure onError(Object error, StackTrace stackTrace)?}) Future<Result<T>>

Available on Future<T>, provided by the FutureToResultX extension

Awaits this future, returning Success on completion or Error if it throws. By default the caught object is wrapped in Failure.unknown; pass onError to translate transport-specific exceptions into a more meaningful Failure.