trait ThereafterAsync[F[_]] extends Thereafter[F]
Extension of Thereafter that adds the possibility to run an asynchronous piece of code afterwards with proper synchronization and exception propagation.
- Alphabetic
- By Inheritance
- ThereafterAsync
- Thereafter
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
- abstract type Content[_]
The container type for computation result.
The container type for computation result.
Must contain at most one element of the given type parameter.
- Definition Classes
- Thereafter
- abstract type Shape
Defines the shapes under which a Content does contain a single element of the type argument.
Defines the shapes under which a Content does contain a single element of the type argument. With withShape
(shape, x)
, we can uniquely reconstruct the Content from a valuex
and itsshape
, which is needed for implementing thereafter in terms of transformChaining.For example, if Content is
Either[String, *]
, then only the formRight(x)
contains such an elementx
. So they are all of the same shapeRight
and so the shape can be any singleton type such asRight.type
orUnit
. Conversely, if Content isTuple2(Int, *)
, then an elementx
can appear in many values, e.g.,(0, x)
and(1, x)
of different shapes. In this case, the shape type would beInt
so that we can reconstruct(0, x)
or(1, x)
from the valuex
and the corresponding shape0
or1
.Formally,
Shape
is the type of one-hole contexts for Content, also known as zippers, which is the derivative of Content/ As such,Shape
should depend on its type argument. However, as Content contains at most element of the given argument type, its derivative is always constant. So we can omit the type argument altogether.- Definition Classes
- Thereafter
- See also
https://en.wikipedia.org/wiki/Zipper_(data_structure)
Abstract Value Members
- abstract def covariantContent[A, B](implicit ev: <:<[A, B]): <:<[Content[A], Content[B]]
Evidences that Content is actually covariant in its type argument.
Evidences that Content is actually covariant in its type argument.
We do not declare Content itself as covariant in the type definition because this would leak into the
Thereafter.Aux
pattern and thereby break the compiler's type inference.- Definition Classes
- Thereafter
- abstract def executionContext: ExecutionContext
- abstract def transformChaining[A](f: F[A])(empty: (Content[Uninhabited]) => Unit, single: (Shape, A) => A): F[A]
Runs either
empty
orsingle
after the computationf
has run.Runs either
empty
orsingle
after the computationf
has run.- If
f
does not produce a value of typeA
,empty
is run. Ifempty
completes normally,f
is returned. Ifempty
throws, the thrown exception is incorporated intof
as follows:- If
f
did not throw an exception, the exception overrides the result off
. - If
f
did throw an exception, the exception fromempty
is added as a suppressed exception.
- If
- Otherwise, if
f
produces a single valuea
of typeA
, then the behavior is equivalent tof.map(single)
.
This method is more general than thereafter because
single
can transform the value. This is necessary for instances such as cats.data.Nested where the nested computation must be transformed, which is not possible with thereafter for the outer computation. Note that a plain functor on the outer computation does not suffice because the transformation of the inner computation could throw and it is not guaranteed that the functor properly chains the exceptions. Nested computations are useful for keeping the several computations distinguishable, such as the synchronous and asynchronous parts of message processing.The signature of
single
separates theShape
from the value to ensure thatsingle
only transforms the value, but does not change the shape. This is crucial for cats.data.Nested as we would otherwise have to be able to replace the inner computation with an empty content of the outer, which doesn't make sense.- Definition Classes
- Thereafter
- If
- abstract def transformChainingF[A](f: F[A])(empty: (Content[Uninhabited]) => Future[Unit], single: (Shape, A) => Future[A]): F[A]
- abstract def withShape[A](shape: Shape, x: A): Content[A]
Plugs the value
x
into the hole of the shape interpreted as a one-hole context.Plugs the value
x
into the hole of the shape interpreted as a one-hole context.- Definition Classes
- Thereafter
Concrete Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @IntrinsicCandidate() @native()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @IntrinsicCandidate() @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @IntrinsicCandidate() @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @IntrinsicCandidate() @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @IntrinsicCandidate() @native()
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def thereafter[A](f: F[A])(body: (Content[A]) => Unit): F[A]
Runs
body
after the computationf
has completed.Runs
body
after the computationf
has completed.- returns
The computation that results from chaining
f
beforebody
. Completes only afterbody
has run. Ifbody
completes normally, the result of the computation is the same asf
's result. Ifbody
throws, the result includes the thrown exception.
- Definition Classes
- Thereafter
- def thereafterF[A](f: F[A])(body: (Content[A]) => Future[Unit]): F[A]
runs
body
after the computationf
has completedruns
body
after the computationf
has completed- returns
The computation that results from chaining
f
beforebody
. Completes only afterbody
has run. Ifbody
completes normally, the result of the computation is the same asf
's result. Ifbody
throws, the result includes the thrown exception. Ifbody
produces a failed computation, the result includes the thrown exception.
- def thereafterFSuccessOrFailure[A](f: F[A])(success: (A) => Future[Unit], failure: => Future[Unit]): F[A]
- def thereafterP[A](f: F[A])(body: PartialFunction[Content[A], Unit]): F[A]
- Definition Classes
- Thereafter
- def thereafterSuccessOrFailure[A](f: F[A])(success: (A) => Unit, failure: => Unit): F[A]
- Definition Classes
- Thereafter
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])