A variant of flatMap
that ignores the value produced by this action.
A variant of flatMap
that ignores the value produced by this action.
Sequences the specified action after this action, but ignores the value produced by the action.
Sequences the specified action after this action, but ignores the value produced by the action.
Executes this action and returns its value, if it succeeds, but otherwise executes the specified action.
Executes this action and returns its value, if it succeeds, but otherwise executes the specified action.
Executes this action and returns its value, if it succeeds, but otherwise executes the specified action.
Executes this action and returns its value, if it succeeds, but otherwise executes the specified action.
Widens the action type to any supertype.
Widens the action type to any supertype. While map
suffices for this
purpose, this method is significantly faster for this purpose.
Executes this action, capturing both failure and success and returning
the result in an Either
.
Executes this action, capturing both failure and success and returning
the result in an Either
. This method is useful for recovering from
IO
actions that may fail.
The error parameter of the returned IO
is Nothing, since
it is guaranteed the IO
action does not raise any errors.
Maps an IO[E, A]
into an IO[E2, B]
by applying the specified E => E2
and
A => B
functions to the output of this action.
Maps an IO[E, A]
into an IO[E2, B]
by applying the specified E => E2
and
A => B
functions to the output of this action. Repeated applications of bimap
(io.bimap(f1, g1).bimap(f2, g2)...bimap(f10000, g20000)
) are guaranteed stack safe to a depth
of at least 10,000.
When this action represents acquisition of a resource (for example,
opening a file, launching a thread, etc.), bracket
can be used to ensure
the acquisition is not interrupted and the resource is released.
When this action represents acquisition of a resource (for example,
opening a file, launching a thread, etc.), bracket
can be used to ensure
the acquisition is not interrupted and the resource is released.
The function does two things:
1. Ensures this action, which acquires the resource, will not be
interrupted. Of course, acquisition may fail for internal reasons (an
uncaught exception).
2. Ensures the release
action will not be interrupted, and will be
executed so long as this action successfully acquires the resource.
In between acquisition and release of the resource, the use
action is
executed.
If the release
action fails, then the entire action will fail even
if the use
action succeeds. If this fail-fast behavior is not desired,
errors produced by the release
action can be caught and ignored.
openFile("data.json").bracket(closeFile) { file => for { header <- readHeader(file) ... } yield result }
A more powerful version of bracket
that provides information on whether
or not use
succeeded to the release action.
A more powerful version of bracket
that provides information on whether
or not use
succeeded to the release action.
Executes the release action only if there was an error.
Executes the release action only if there was an error.
A less powerful variant of bracket
where the value produced by this
action is not needed.
A less powerful variant of bracket
where the value produced by this
action is not needed.
Recovers from all errors.
Recovers from all errors.
openFile("config.json").catchAll(_ => IO.now(defaultConfig))
Recovers from some or all of the error cases.
Recovers from some or all of the error cases.
openFile("data.json").catchSome { case FileNotFoundException(_) => openFile("backup.json") }
Maps this action to the specified constant while preserving the effects of this action.
Maps this action to the specified constant while preserving the effects of this action.
Delays this action by the specified amount of time.
Delays this action by the specified amount of time.
Executes the specified finalizer, whether this action succeeds, fails, or is interrupted.
Executes the specified finalizer, whether this action succeeds, fails, or is interrupted. This method should not be used for cleaning up resources, because it's possible the fiber will be interrupted after acquisition but before the finalizer is added.
Creates a composite action that represents this action followed by another one that may depend on the value produced by this one.
Creates a composite action that represents this action followed by another one that may depend on the value produced by this one.
val parsed = readFile("foo.txt").flatMap(file => parseFile(file))
Repeats this action forever (until the first error).
Repeats this action forever (until the first error). For more sophisticated
schedules, see the repeat
method.
Forks this action into its own separate fiber, returning immediately without the value produced by this action.
Forks this action into its own separate fiber, returning immediately without the value produced by this action.
The Fiber[E, A]
returned by this action can be used to interrupt the
forked fiber with some exception, or to join the fiber to "await" its
computed value.
for { fiber <- subtask.fork // Do stuff... a <- subtask.join } yield a
A more powerful version of fork
that allows specifying a handler to be
invoked on any exceptions that are not handled by the forked fiber.
A more powerful version of fork
that allows specifying a handler to be
invoked on any exceptions that are not handled by the forked fiber.
Maps over the error type.
Maps over the error type. This can be used to lift a "smaller" error into a "larger" error.
Maps an IO[E, A]
into an IO[E, B]
by applying the specified A => B
function
to the output of this action.
Maps an IO[E, A]
into an IO[E, B]
by applying the specified A => B
function
to the output of this action. Repeated applications of map
(io.map(f1).map(f2)...map(f10000)
) are guaranteed stack safe to a depth
of at least 10,000.
Runs the cleanup action if this action errors, providing the error to the cleanup action if it exists.
Runs the cleanup action if this action errors, providing the error to the cleanup action if it exists. The cleanup action will not be interrupted.
Executes this action and returns its value, if it succeeds, but otherwise executes the specified action.
Executes this action and returns its value, if it succeeds, but otherwise executes the specified action.
Executes both this action and the specified action in parallel, returning a tuple of their results.
Executes both this action and the specified action in parallel, returning a tuple of their results. If either individual action fails, then the returned action will fail.
Executes both this action and the specified action in parallel,
combining their results using given function f
.
Executes both this action and the specified action in parallel,
combining their results using given function f
.
If either individual action fails, then the returned action will fail.
TODO: Replace with optimized primitive.
Calls the provided function with the result of this action, and sequences the resulting action after this action, but ignores the value produced by the action.
Calls the provided function with the result of this action, and sequences the resulting action after this action, but ignores the value produced by the action.
readFile("data.json").peek(putStrLn)
Races this action with the specified action, returning the first
result to produce an A
, whichever it is.
Races this action with the specified action, returning the first
result to produce an A
, whichever it is. If neither action succeeds,
then the action will fail with some error.
Races this action with the specified action, returning the first result to produce a value, whichever it is.
Races this action with the specified action, returning the first result to produce a value, whichever it is. If neither action succeeds, then the action will fail with some error.
Races this action with the specified action, invoking the specified finisher as soon as one value or the other has been computed.
Races this action with the specified action, invoking the specified finisher as soon as one value or the other has been computed.
Recovers from errors by accepting one action to execute for the case of an error, and one action to execute for the case of success.
Recovers from errors by accepting one action to execute for the case of an error, and one action to execute for the case of success.
This method has better performance than attempt
since no intermediate
value is allocated and does not requiere subsequent calls to flatMap
to
define the next action.
The error parameter of the returned IO
may be chosen arbitrarily, since
it will depend on the IO
s returned by the given continuations.
Less powerful version of redeem
which always returns a successful
IO[E2, B]
after applying one of the given mapping functions depending
on the result of this
IO
Less powerful version of redeem
which always returns a successful
IO[E2, B]
after applying one of the given mapping functions depending
on the result of this
IO
Repeats this action with the specified schedule.
Repeats this action with the specified schedule.
Retries with the specified retry policy.
Retries with the specified retry policy.
Retries with the specified schedule, until it fails, and then both the value produced by the schedule together with the last error are passed to the recovery function.
Retries with the specified schedule, until it fails, and then both the value produced by the schedule together with the last error are passed to the recovery function.
Retries with the specified schedule, until it fails, and then both the value produced by the schedule together with the last error are passed to the recovery function.
Retries with the specified schedule, until it fails, and then both the value produced by the schedule together with the last error are passed to the recovery function.
Runs this action in a new fiber, resuming when the fiber terminates.
Runs this action in a new fiber, resuming when the fiber terminates.
Companion helper to sandboxed
.
Companion helper to sandboxed
.
Has a performance penalty due to forking a new fiber.
Allows recovery, and partial recovery, from errors and defects alike, as in:
case class DomainError() val veryBadIO: IO[DomainError, Unit] = IO.sync(5 / 0) *> IO.fail(DomainError()) val caught: IO[DomainError, Unit] = veryBadIO.sandboxWith(_.catchSome { case Left((_: ArithmeticException) :: Nil) => // Caught defect: divided by zero! IO.now(0) })
Using sandboxWith
with catchSome
is better than using
io.sandboxed.catchAll
with a partial match, because in
the latter, if the match fails, the original defects will
be lost and replaced by a MatchError
Runs this action in a new fiber, resuming when the fiber terminates.
Runs this action in a new fiber, resuming when the fiber terminates.
If the fiber fails with an error it will be captured in Right side of the error Either If the fiber terminates because of defect, list of defects will be captured in the Left side of the Either
Allows recovery from errors and defects alike, as in:
case class DomainError() val veryBadIO: IO[DomainError, Unit] = IO.sync(5 / 0) *> IO.fail(DomainError()) val caught: IO[Nothing, Unit] = veryBadIO.sandboxed.catchAll { case Left((_: ArithmeticException) :: Nil) => // Caught defect: divided by zero! IO.now(0) case Left(ts) => // Caught unknown defects, shouldn't recover! IO.terminate0(ts) case Right(e) => // Caught error: DomainError! IO.now(0) }
Sequentially zips this effect with the specified effect, combining the results into a tuple.
Sequentially zips this effect with the specified effect, combining the results into a tuple.
Sequentially zips this effect with the specified effect using the specified combiner function.
Sequentially zips this effect with the specified effect using the specified combiner function.
Summarizes a action by computing some value before and after execution, and then combining the values to produce a summary, together with the result of execution.
Summarizes a action by computing some value before and after execution, and then combining the values to produce a summary, together with the result of execution.
Supervises this action, which ensures that any fibers that are forked by the action are handled by the provided supervisor.
Supervises this action, which ensures that any fibers that are forked by the action are handled by the provided supervisor.
Supervises this action, which ensures that any fibers that are forked by the action are interrupted when this action completes.
Supervises this action, which ensures that any fibers that are forked by the action are interrupted when this action completes.
An integer that identifies the term in the IO
sum type to which this
instance belongs (e.g.
An integer that identifies the term in the IO
sum type to which this
instance belongs (e.g. IO.Tags.Point
).
Returns a new action that executes this one and times the execution.
Returns a new action that executes this one and times the execution.
A more powerful variation of timed
that allows specifying the clock.
A more powerful variation of timed
that allows specifying the clock.
Times out this action by the specified duration.
Times out this action by the specified duration.
IO.point(1).timeout(Option.empty[Int])(Some(_))(1.second)
Performs this action non-interruptibly.
Performs this action non-interruptibly. This will prevent the action from being terminated externally, but the action may fail for internal reasons (e.g. an uncaught error) or terminate due to defect.
Maps this action to one producing unit, but preserving the effects of this action.
Maps this action to one producing unit, but preserving the effects of this action.