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
durationafter evaluating and then return the result. -
ap<
B> (covariant IO< Function1< f) → IO<A, B> >B> -
Apply
fto 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
Eithervalue. -
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,
useas the IO action that action that uses the resource, andreleaseas 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,
useas the IO action that action that uses the resource, andreleaseas the finalizer that will clean up the resource. Both result of this IO and the Outcome ofuseare 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
durationbefore 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
fthat will create the next IO to be evaluated. -
flatMapN<
D> (Function3< A, B, C, IO< f) → IO<D> >D> -
Available on IO<
(A, B, C)> , provided by the IOTuple3Ops extension -
flatMapN<
C> (Function2< A, B, IO< f) → IO<C> >C> -
Available on IO<
(A, B)> , provided by the IOTuple2Ops extension -
flatTap<
B> (covariant Function1< A, IO< f) → IO<B> >A> -
Performs the side-effect encoded in
fusing the value created by this IO, then returning the original value. -
flatTapN<
D> (Function3< A, B, C, IO< f) → IO<D> >(A, B, C)> -
Available on IO<
(A, B, C)> , provided by the IOTuple3Ops extension -
flatTapN<
C> (Function2< A, B, IO< f) → IO<C> >(A, B)> -
Available on IO<
(A, B)> , provided by the IOTuple2Ops extension -
flatten(
) → IO< A> -
Available on IO<
Returns an IO that will complete with the value of the inner IO.IO< , provided by the IONestedOps extensionA> > -
foreverM(
) → IO< Never> - Continually re-evaluate this IO forever, until an error or cancelation.
-
guarantee(
IO< Unit> fin) → IO<A> -
Executes the provided finalizer
finregardless of the Outcome of evaluating this IO. -
guaranteeCase(
Function1< Outcome< fin) → IO<A> , IO<Unit> >A> -
Executes the provided finalizer
finwhich 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. -
ifM<
B> (Function0< IO< ifTrue, Function0<B> >IO< ifFalse) → IO<B> >B> -
Available on IO<
Returns the evaluation ofbool> , provided by the IOBoolOps extensionifTruewhen the value of this IO evaluates to true, otherwise returnsifFalse. -
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 satisfiespwill 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 satisfypwill be the final result. -
map<
B> (covariant Function1< A, B> f) → IO<B> -
Applies
fto the value of this IO, returning the result. -
mapN<
D> (Function3< A, B, C, D> f) → IO<D> -
Available on IO<
(A, B, C)> , provided by the IOTuple3Ops extension -
mapN<
C> (Function2< A, B, C> f) → IO<C> -
Available on IO<
(A, B)> , provided by the IOTuple2Ops extension -
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
thatas an attempt to recover. -
parReplicate(
int n) → IO< IList< A> > -
Runs this IO
ntimes, accumulating the result from each evaluation into anIList. All replications will be run asynchronously. -
parReplicate_(
int n) → IO< Unit> -
Runs this IO
ntimes, 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
recoverormap, 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
recoveror map, depending on whether this IO results in an error or is successful. -
replicate(
int n) → IO< IList< A> > -
Runs this IO
ntimes, accumulating the result from each evaluation into anIList. -
replicate_(
int n) → IO< Unit> -
Runs this IO
ntimes, discarding any resulting values. -
rethrowError(
) → IO< A> -
Available on IO<
Inverse of IO.attempt.Either< , provided by the IOExceptionOps extensionException, A> > -
retrying(
RetryPolicy policy, {Function1< A, bool> ? wasSuccessful, Function1<RuntimeException, bool> ? isWorthRetrying, Function2<RuntimeException, RetryDetails, IO< ? onError, Function2<Unit> >A, RetryDetails, IO< ? onFailure}) → IO<Unit> >A> -
Available on IO<
Applies the givenA> , provided by the RetryOps extensionpolicyto this IO and will attempt to retry any failed attempts according to the policy. -
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
fallbackif 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, withbtaking the first element of the tuple. -
tupleLeftN<
C> (C c) → IO< (C, A, B)> -
Available on IO<
(A, B)> , provided by the IOTuple2Ops extension -
tupleLeftN<
D> (D d) → IO< (D, A, B, C)> -
Available on IO<
(A, B, C)> , provided by the IOTuple3Ops extension -
tupleRight<
B> (B b) → IO< (A, B)> -
Creates an IO that will return the value of this IO tupled with
b, withbtaking the second element of the tuple. -
tupleRightN<
C> (C c) → IO< (A, B, C)> -
Available on IO<
(A, B)> , provided by the IOTuple2Ops extension -
tupleRightN<
D> (D d) → IO< (A, B, C, D)> -
Available on IO<
(A, B, C)> , provided by the IOTuple3Ops extension -
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
cbwith 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
condresults istrue. Results from every evaluation is accumulated in the returnedIList. -
untilM_(
IO< bool> cond) → IO<Unit> -
Evaluates this IO repeatedly until evaluating
condresults istrue. Results are discarded. -
voided(
) → IO< Unit> -
Discards the value of this IO and replaces it with
Unit. -
voidError(
) → IO< Unit> - Ignores any errors.
-
whilelM(
IO< bool> cond) → IO<IList< A> > -
Evaluates this IO repeatedly until evaluating
condresults isfalse. Results from every evaluation is accumulated in the returnedIList. -
whileM_(
IO< bool> cond) → IO<Unit> -
Evaluates this IO repeatedly until evaluating
condresults 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
kwithin 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
kwithin 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
ioaandiobtogether, 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
ioaandiob, 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 touseif successful and then guarantee the evaluation ofrelease. -
defer<
A> (Function0< IO< thunk) → IO<A> >A> -
Suspends the synchronous evaluation of
thunkin 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
thunkin 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.purewheneitherisRight, orIO.raiseErrorwitheitherproviding the error wheneitherisLeft. -
fromFuture<
A> (IO< Future< fut) → IO<A> >A> -
Create an IO that returns the value of the underlying Future or
the error
futemits. -
fromFutureF<
A> (Function0< Future< futF) → IO<A> >A> -
Create an IO that returns the value of the underlying Future function
or the error
futFemits. -
fromOption<
A> (Option< A> option, Function0<Object> orElse) → IO<A> -
Alias for
IO.purewhenoptionisSome, orIO.raiseErrorwithorElseproviding the error whenoptionisNone. -
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
messageto stdout, delaying the effect until evaluation. -
printErr(
String message) → IO< Unit> -
Writes
messageto stderr, delaying the effect until evaluation. -
printErrLn(
String message) → IO< Unit> -
Writes
messagewith a newline to stderr, delaying the effect until evaluation. -
println(
String message) → IO< Unit> -
Writes
messagewith 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
ioaandiobtogether, 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
ioaandiobtogether, 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
ioaandiobtogether, 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.raiseErrorwhencondis false, otherwiceIO.unit. -
raiseWhen(
bool cond, Function0< RuntimeException> e) → IO<Unit> -
Returns an
IO.raiseErrorwhencondis 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
durationand 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
actionargument whencondis false, otherwise returns IO.unit. -
whenA<
A> (bool cond, Function0< IO< action) → IO<A> >Unit> -
Returns the
actionargument whencondis true, otherwise returns IO.unit.