AsyncQueryResult<T>.from constructor Null safety

AsyncQueryResult<T>.from(
  1. StatedResult result
)

Create AsyncQueryResult from any other result

PendingResult converts to AsyncQueryResult.pending InitialValueResult converts to AsyncQueryResult.initialValue WaitingResult converts to AsyncQueryResult.waiting FailedResult converts to AsyncQueryResult.failed SucceededResult with type T converts to AsyncQueryResult.succeeded Otherwise UnsupportedError is thrown

Implementation

factory AsyncQueryResult.from(StatedResult result) =>
    result.unsafeMapOr<T, AsyncQueryResult<T>>(
      pendingResult: () => AsyncQueryResult.pending(),
      initialValueResult: (result) =>
          AsyncQueryResult.initialValue(result.value),
      waitingResult: () => AsyncQueryResult.waiting(),
      failedResult: (result) =>
          AsyncQueryResult.failed(result.error, result.stackTrace),
      succeededResult: (result) => AsyncQueryResult.succeeded(result.value),
      orElse: () => throw UnsupportedError(
          "Cannot convert $result to AsyncQueryResult"),
    );