IO<A> class
sealed
IO is a datatype that can be used to control side-effects within synchronous and asynchronous code.
- Available extensions
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
andWait(
Duration duration) → IO< A> -
Return an IO that will wait the specified
duration
after evaluating and then return the result. -
ap<
B> (covariant IO< Function1< f) → IO<A, B> >B> -
Apply
f
to the value of thisApplicative
. -
as<
B> (B b) → IO< B> - Replaces the result of this IO with the given value.
-
attempt(
) → IO< Either< RuntimeException, A> > -
Extracts any exceptions encountered during evaluation into an
Either
value. -
background(
) → Resource< IO< Outcome< >A> > - Creates a new Resource that will start the execution of this fiber and cancel the execution when the Resource is finalized.
-
bracket<
B> (Function1< A, IO< use, Function1<B> >A, IO< release) → IO<Unit> >B> -
Returns an IO that uses this IO as the resource acquisition,
use
as the IO action that action that uses the resource, andrelease
as the finalizer that will clean up the resource. -
bracketCase<
B> (Function1< A, IO< use, Function2<B> >A, Outcome< release) → IO<B> , IO<Unit> >B> -
Returns an IO that uses this IO as the resource acquisition,
use
as the IO action that action that uses the resource, andrelease
as the finalizer that will clean up the resource. Both result of this IO and the Outcome ofuse
are provided torelease
. -
cancelable(
IO< Unit> fin) → IO<A> -
debug(
{String prefix = 'DEBUG'}) → IO< A> - Prints the result of this IO (value, error or canceled) to stdout
-
delayBy(
Duration duration) → IO< A> -
Return an IO that will wait the specified
duration
before evaluating and then return the result. -
flatMap<
B> (covariant Function1< A, IO< f) → IO<B> >B> -
Sequences the evaluation of this IO and the provided function
f
that will create the next IO to be evaluated. -
flatTap<
B> (covariant Function1< A, IO< f) → IO<B> >A> -
Performs the side-effect encoded in
f
using the value created by this IO, then returning the original value. -
foreverM(
) → IO< Never> - Continually re-evaluate this IO forever, until an error or cancelation.
-
guarantee(
IO< Unit> fin) → IO<A> -
Executes the provided finalizer
fin
regardless of the Outcome of evaluating this IO. -
guaranteeCase(
Function1< Outcome< fin) → IO<A> , IO<Unit> >A> -
Executes the provided finalizer
fin
which can decide what action to take depending on the Outcome of this IO. -
handleError(
Function1< RuntimeException, A> f) → IO<A> -
Intercepts any upstream Exception, returning the value generated by
f
. -
handleErrorWith(
covariant Function1< RuntimeException, IO< f) → IO<A> >A> -
Intercepts any upstream Exception, sequencing in the IO generated by
f
. -
isolate(
{String? debugName}) → IO< A> -
iterateUntil(
Function1< A, bool> p) → IO<A> -
Continually re-evaluates this IO until the computed value satisfies the
given predicate
p
. The first computed value that satisfiesp
will be the final result. -
iterateWhile(
Function1< A, bool> p) → IO<A> -
Continually re-evaluates this IO while the computed value satisfies the
given predicate
p
. The first computed value that does not satisfyp
will be the final result. -
map<
B> (covariant Function1< A, B> f) → IO<B> -
Applies
f
to the value of this IO, returning the result. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onCancel(
IO< Unit> fin) → IO<A> - Attaches a finalizer to this IO that will be evaluated if this IO is canceled.
-
onError(
covariant Function1< RuntimeException, IO< f) → IO<Unit> >A> - Performs the given side-effect if this IO results in a error.
-
option(
) → IO< Option< A> > -
Replaces any failures from this IO with
None
. A successful value is wrapped inSome
. -
orElse(
Function0< IO< that) → IO<A> >A> -
If the evaluation of this IO results in an error, run
that
as an attempt to recover. -
parReplicate(
int n) → IO< IList< A> > -
Runs this IO
n
times, accumulating the result from each evaluation into anIList
. All replications will be run asynchronously. -
parReplicate_(
int n) → IO< Unit> -
Runs this IO
n
times, discarding any resulting values. All replications will be run asynchronously. -
product<
B> (IO< B> that) → IO<(A, B)> -
Sequentially evaluate this IO, then
that
, and return the product (i.e. tuple) of each value. -
productL<
B> (Function0< IO< that) → IO<B> >A> -
Sequentially evaluate this IO, then
that
, returning the value producted by this, discarding that value fromthat
. -
productR<
B> (Function0< IO< that) → IO<B> >B> -
Sequentially evaluate this IO, then
that
, returning the value producted bythat
, discarding the value from this. -
redeem<
B> (Function1< RuntimeException, B> recover, Function1<A, B> map) → IO<B> -
Returns the value created from
recover
ormap
, depending on whether this IO results in an error or is successful. -
redeemWith<
B> (Function1< RuntimeException, IO< recover, Function1<B> >A, IO< bind) → IO<B> >B> -
Returns the value created from
recover
or map, depending on whether this IO results in an error or is successful. -
replicate(
int n) → IO< IList< A> > -
Runs this IO
n
times, accumulating the result from each evaluation into anIList
. -
replicate_(
int n) → IO< Unit> -
Runs this IO
n
times, discarding any resulting values. -
start(
) → IO< IOFiber< A> > - Starts the execution of this IO, returning a handle to the running IO in the form of an IOFiber. The fiber can be used to wait for a result or cancel it's execution.
-
timed(
) → IO< (Duration, A)> - Times how long this IO takes to evaluate, and returns the Duration and the value as a tuple.
-
timeout(
Duration duration) → IO< A> -
Creates an IO that returns the value of this IO, or raises an error
if the evaluation take longer than
duration
. -
timeoutAndForget(
Duration duration) → IO< A> -
timeoutTo(
Duration duration, IO< A> fallback) → IO<A> -
Creates an IO that will return the value of this IO, or the value of
fallback
if the evaluation of this IO exceedsduration
. -
toResource(
) → Resource< A> - Lifts this IO to a Resource
-
toString(
) → String -
A string representation of this object.
inherited
-
toSyncIO(
int limit) → SyncIO< Either< IO< >A> , A> -
tupleLeft<
B> (B b) → IO< (B, A)> -
Creates an IO that will return the value of this IO tupled with
b
, withb
taking the first element of the tuple. -
tupleRight<
B> (B b) → IO< (A, B)> -
Creates an IO that will return the value of this IO tupled with
b
, withb
taking the second element of the tuple. -
unsafeRunAndForget(
{int autoCedeN = IOFiber.DefaultAutoCedeN}) → void - Starts the evaluation of this IO and discards any results.
-
unsafeRunAsync(
Function1< Outcome< cb, {int autoCedeN = IOFiber.DefaultAutoCedeN}) → voidA> , void> -
Starts the evaluation this IO and invokes the given callback
cb
with the Outcome. -
unsafeRunCancelable(
{int autoCedeN = IOFiber.DefaultAutoCedeN}) → Function0< Future< Unit> > - Starts the evaluation of this IO and returns a function that can be called to cancel the evaluation. If the evaluation has already finished, the cancelation function is a no-op.
-
unsafeRunFuture(
{int autoCedeN = IOFiber.DefaultAutoCedeN}) → Future< A> - Starts the evaluation of this IO and returns a Future that will complete with the Outcome of the evaluation. The Future may complete with an error if the evaluation of the IO encounters and error or is canceled.
-
unsafeRunFutureCancelable(
{int autoCedeN = IOFiber.DefaultAutoCedeN}) → (Future< A> , Function0<Future< )Unit> > - Starts the evaluation of this IO and returns a Future that will complete with the Outcome of the evaluation as well as a function that can be called to cancel the future. The Future will not complete with an error, since the value itself is capable of conveying an error was encountered. If the evaluation has already finished, the cancelation function is a no-op.
-
unsafeRunFutureOutcome(
{int autoCedeN = IOFiber.DefaultAutoCedeN}) → Future< Outcome< A> > - Evaluates this IO and returns a Future that will complete with the Outcome of the evaluation. The Future will not complete with an error, since the value itself is capable of conveying an error was encountered.
-
untilM(
IO< bool> cond) → IO<IList< A> > -
Evaluates this IO repeatedly until evaluating
cond
results istrue
. Results from every evaluation is accumulated in the returnedIList
. -
untilM_(
IO< bool> cond) → IO<Unit> -
Evaluates this IO repeatedly until evaluating
cond
results istrue
. Results are discarded. -
voided(
) → IO< Unit> -
Discards the value of this IO and replaces it with
Unit
. -
whilelM(
IO< bool> cond) → IO<IList< A> > -
Evaluates this IO repeatedly until evaluating
cond
results isfalse
. Results from every evaluation is accumulated in the returnedIList
. -
whileM_(
IO< bool> cond) → IO<Unit> -
Evaluates this IO repeatedly until evaluating
cond
results isfalse
. Results are discarded.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
-
canceled
↔ IO<
Unit> -
Creates an IO that immediately results in an Outcome of Canceled.
getter/setter pair
-
cede
↔ IO<
Unit> -
Introduces an asynchronous boundary in the IO runtime loop that can
be used for cancelation checking and fairness, among other things.
getter/setter pair
-
now
↔ IO<
DateTime> -
Returns the current DateTime when evaluation occurs.
getter/setter pair
-
stub
→ IO<
Never> -
Alias for
IO.delay(() => throw UnimplementedError())
no setter -
unit
↔ IO<
Unit> -
Alias for
IO.pure(Unit())
.getter/setter pair
Static Methods
-
async<
A> (AsyncBodyWithFin< A> k) → IO<A> -
Suspends the asynchronous effect
k
within IO. When evaluation is completed, the callback will be invoked with the result of the IO. If the newly created IO is canceled, the provided finalizer will be invoked. -
async_<
A> (AsyncBody< A> k) → IO<A> -
Suspends the asynchronous effect
k
within IO. When evaluation is completed, the callback will be invoked with the result of the IO. -
both<
A, B> (IO< A> ioa, IO<B> iob) → IO<(A, B)> -
Runs both
ioa
andiob
together, returning a tuple of both results if both of them are successful. If either of them results in an error or is canceled, that error or cancelation is propogated. -
bothOutcome<
A, B> (IO< A> ioa, IO<B> iob) → IO<(Outcome< A> , Outcome<B> )> -
Runs both
ioa
andiob
, returning a tuple of the Outcome of each. -
bracketFull<
A, B> (Function1< Poll, IO< acquire, Function1<A> >A, IO< use, Function2<B> >A, Outcome< release) → IO<B> , IO<Unit> >B> -
Creates an IO that will evaluate
acquire
, pass the result touse
if successful and then guarantee the evaluation ofrelease
. -
defer<
A> (Function0< IO< thunk) → IO<A> >A> -
Suspends the synchronous evaluation of
thunk
in IO. -
deferred<
A> () → IO< Deferred< A> > - Creates a new Deferred of the given generic type.
-
delay<
A> (Function0< A> thunk) → IO<A> -
Suspends the synchronous evaluation of
thunk
in IO. -
exec<
A> (Function0< A> thunk) → IO<Unit> - Executes the given function, discarding any result.
-
fromCancelableOperation<
A> (IO< CancelableOperation< op) → IO<A> >A> -
Creates an IO that returns the value or error of the underlying
CancelableOperation
. If new IO is canceled, the cancelation request will be forwarded to the underlyingCancelableOperation
. -
fromEither<
A> (Either< Object, A> either) → IO<A> -
Alias for
IO.pure
wheneither
isRight
, orIO.raiseError
witheither
providing the error wheneither
isLeft
. -
fromFuture<
A> (IO< Future< fut) → IO<A> >A> -
Create an IO that returns the value of the underlying Future or
the error
fut
emits. -
fromFutureF<
A> (Function0< Future< futF) → IO<A> >A> -
Create an IO that returns the value of the underlying Future function
or the error
futF
emits. -
fromOption<
A> (Option< A> option, Function0<Object> orElse) → IO<A> -
Alias for
IO.pure
whenoption
isSome
, orIO.raiseError
withorElse
providing the error whenoption
isNone
. -
never<
A> () → IO< A> -
Returns a non-terminating IO, alias for
async_((_) {})
. -
none<
A> () → IO< Option< A> > -
Alias for
IO.pure(const None())
. -
print(
String message) → IO< Unit> -
Writes
message
to stdout, delaying the effect until evaluation. -
printErr(
String message) → IO< Unit> -
Writes
message
to stderr, delaying the effect until evaluation. -
printErrLn(
String message) → IO< Unit> -
Writes
message
with a newline to stderr, delaying the effect until evaluation. -
println(
String message) → IO< Unit> -
Writes
message
with a newline to stdout, delaying the effect until evaluation. -
pure<
A> (A a) → IO< A> - Lifts a pure value into IO.
-
race<
A, B> (IO< A> ioa, IO<B> iob) → IO<Either< A, B> > -
Runs
ioa
andiob
together, returning the first IO to finish after the loser is canceled. -
raceOutcome<
A, B> (IO< A> ioa, IO<B> iob) → IO<Either< Outcome< >A> , Outcome<B> > -
Runs
ioa
andiob
together, returning the Outcome of the winner after canceling the loser. -
racePair<
A, B> (IO< A> ioa, IO<B> iob) → IO<Either< AWon< >A, B> , BWon<A, B> > -
Runs
ioa
andiob
together, returning a pair of the Outcome of the IO that finished first (won) and an IOFiber handle for the loser. -
raiseError<
A> (RuntimeException error) → IO< A> - Create an IO that will inject the given error into the IO evaluation.
-
raiseUnless(
bool cond, Function0< RuntimeException> e) → IO<Unit> -
Returns an
IO.raiseError
whencond
is false, otherwiceIO.unit
. -
raiseWhen(
bool cond, Function0< RuntimeException> e) → IO<Unit> -
Returns an
IO.raiseError
whencond
is true, otherwiceIO.unit
. -
readLine(
) → IO< String> - Reads a line from stdin. This is a blocking operation and will not finish until a full line of input is available from the console.
-
ref<
A> (A a) → IO< Ref< A> > - Creates a new Ref of the given generic type.
-
sleep(
Duration duration) → IO< Unit> -
Creates an ansynchronous IO that will sleep for the given
duration
and resume when finished. -
some<
A> (A a) → IO< Option< A> > -
Alias for
IO.pure(Some(a))
. -
uncancelable<
A> (Function1< Poll, IO< body) → IO<A> >A> - Creates an uncancelable region within the IO run loop. The Poll provided can be used to create unmasked cancelable regions within the uncancelable region.
-
unlessA<
A> (bool cond, Function0< IO< action) → IO<A> >Unit> -
Returns the
action
argument whencond
is false, otherwise returns IO.unit. -
whenA<
A> (bool cond, Function0< IO< action) → IO<A> >Unit> -
Returns the
action
argument whencond
is true, otherwise returns IO.unit.