Creates a simple, noncancelable F[A]
instance that
executes an asynchronous process on evaluation.
Creates a simple, noncancelable F[A]
instance that
executes an asynchronous process on evaluation.
The given function is being injected with a side-effectful callback for signaling the final result of an asynchronous process.
is a function that should be called with a callback for signaling the result once it is ready
A generalized version of bracket which uses ExitCase to distinguish between different exit cases when releasing the acquired resource.
A generalized version of bracket which uses ExitCase to distinguish between different exit cases when releasing the acquired resource.
is an action that "acquires" some expensive resource, that needs to be used and then discarded
is the action that uses the newly allocated resource and that will provide the final result
is the action that's supposed to release the
allocated resource after use
is done, by observing
and acting on its exit condition
Suspends the evaluation of an F
reference.
Suspends the evaluation of an F
reference.
Equivalent to FlatMap.flatten
for pure expressions,
the purpose of this function is to suspend side effects
in F
.
Operation meant for specifying tasks with safe resource acquisition and release in the face of errors and interruption.
Operation meant for specifying tasks with safe resource acquisition and release in the face of errors and interruption.
This operation provides the equivalent of try/catch/finally
statements in mainstream imperative languages for resource
acquisition and release.
is an action that "acquires" some expensive resource, that needs to be used and then discarded
is the action that uses the newly allocated resource and that will provide the final result
is the action that's supposed to release the
allocated resource after use
is done, irregardless of
its exit condition
Lifts any by-name parameter into the F
context.
Lifts any by-name parameter into the F
context.
Equivalent to Applicative.pure
for pure expressions,
the purpose of this function is to suspend side effects
in F
.
Inherited from LiftIO, defines a conversion from IO
in terms of the Async
type class.
Inherited from LiftIO, defines a conversion from IO
in terms of the Async
type class.
N.B. expressing this conversion in terms of Async
and its
capabilities means that the resulting F
is not cancelable.
Concurrent then overrides this with an implementation
that is.
To access this implementation as a standalone function, you can use Async.liftIO (on the object companion).
Returns a non-terminating F[_]
, that never completes
with a result, being equivalent to async(_ => ())
(Since version 1.0.0-RC2) Use *> or productR instead.
(Since version 1.0.0-RC2) Use productREval instead.
(Since version 1.0.0-RC2) Use <* or productL instead.
(Since version 1.0.0-RC2) Use productLEval instead.
A monad that can describe asynchronous or synchronous computations that produce exactly one result.
On Asynchrony
An asynchronous task represents logic that executes independent of the main program flow, or current callstack. It can be a task whose result gets computed on another thread, or on some other machine on the network.
In terms of types, normally asynchronous processes are represented as:
This signature can be recognized in the "Observer pattern" described in the "Gang of Four", although it should be noted that without an
onComplete
event (like in the Rx Observable pattern) you can't detect completion in case this callback can be called zero or multiple times.Some abstractions allow for signaling an error condition (e.g.
MonadError
data types), so this would be a signature that's closer to Scala'sFuture#onComplete
:And many times the abstractions built to deal with asynchronous tasks also provide a way to cancel such processes, to be used in race conditions in order to cleanup resources early:
This is approximately the signature of JavaScript's
setTimeout
, which will return a "task ID" that can be used to cancel it.N.B. this type class in particular is NOT describing cancelable async processes, see the Concurrent type class for that.
Async Type class
This type class allows the modeling of data types that:
N.B. on the "one result" signaling, this is not an exactly once requirement. At this point streaming types can implement
Async
and such an exactly once requirement is only clear in Effect.Therefore the signature exposed by the async builder is this:
N.B. such asynchronous processes are not cancelable. See the Concurrent alternative for that.