cats.effect.kernel.Outcome
See theOutcome companion object
sealed trait Outcome[F[_], E, A] extends Product, Serializable
Represents the result of the execution of a fiber. It may terminate in one of 3 states:
- Succeeded(fa) The fiber completed with a value.
A commonly asked question is why this wraps a value of type F[A]
rather than one of type A
. This is to support monad transformers. Consider
val oc: OutcomeIO[Int] =
for {
fiber <- Spawn[OptionT[IO, *]].start(OptionT.none[IO, Int])
oc <- fiber.join
} yield oc
If the fiber succeeds then there is no value of type Int
to be wrapped in Succeeded
, hence Succeeded
contains a value of type OptionT[IO, Int]
instead.
In general you can assume that binding on the value of type F[A]
contained in Succeeded
does not perform further effects. In the case of IO
that means that the outcome has been constructed as Outcome.Succeeded(IO.pure(result))
.
-
Errored(e) The fiber exited with an error.
-
Canceled() The fiber was canceled, either externally or self-canceled via
MonadCancel[F]#canceled
.
Attributes
- Companion
- object
- Source
- Outcome.scala
- Graph
-
- Supertypes
- Known subtypes
Members list
In this article