AsyncActionResult.from constructor Null safety

AsyncActionResult.from(
  1. StatedResult result
)

Create AsyncActionResult from any other result

PendingResult, InitialValueResult converts to AsyncActionResult.pending WaitingResult converts to AsyncActionResult.waiting FailedResult converts to AsyncActionResult.failed CompletedResult, SucceededResult converts to AsyncActionResult.completed Otherwise UnsupportedError is thrown

Implementation

factory AsyncActionResult.from(StatedResult result) =>
    result.unsafeMapOr<dynamic, AsyncActionResult>(
      isNotStarted: () => AsyncActionResult.pending(),
      waitingResult: () => AsyncActionResult.waiting(),
      failedResult: (result) =>
          AsyncActionResult.failed(result.error, result.stackTrace),
      isSucceeded: () => AsyncActionResult.completed(),
      orElse: () => throw UnsupportedError(
          "Cannot convert $result to AsyncActionResult"),
    );