object IO extends IOCompanionPlatform with IOLowPriorityImplicits with TupleParallelSyntax with Serializable
- Source
- IO.scala
- Alphabetic
- By Inheritance
- IO
- Serializable
- TupleParallelSyntax
- IOLowPriorityImplicits
- IOCompanionPlatform
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
- implicit class IOFlatSequenceOps[T[_], A] extends AnyRef
- class IOMonoid[A] extends IOSemigroup[A] with Monoid[IO[A]]
- Attributes
- protected
- class IOSemigroup[A] extends Semigroup[IO[A]]
- Attributes
- protected
- Definition Classes
- IOLowPriorityImplicits
- class IOSemigroupK extends SemigroupK[IO]
- Attributes
- protected
- implicit class IOSequenceOps[T[_], A] extends AnyRef
- type Par[A] = T[IO, A]
Newtype encoding for an
IOdatatype that has acats.Applicativecapable of doing parallel processing inapandmap2, needed for implementingcats.Parallel.Newtype encoding for an
IOdatatype that has acats.Applicativecapable of doing parallel processing inapandmap2, needed for implementingcats.Parallel.For converting back and forth you can use either the
Parallel[IO]instance or the methodscats.effect.kernel.Par.ParallelF.applyfor wrapping anyIOvalue andcats.effect.kernel.Par.ParallelF.valuefor unwrapping it.The encoding is based on the "newtypes" project by Alexander Konovalov, chosen because it's devoid of boxing issues and a good choice until opaque types will land in Scala.
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
- implicit def alignForIO: Align[IO]
- implicit def alignForIOPar: Align[Par]
- def apply[A](thunk: => A): IO[A]
Suspends a synchronous side effect in
IO.Suspends a synchronous side effect in
IO. Use IO.apply if your side effect is not thread-blocking; otherwise you should use IO.blocking (uncancelable) orIO.interruptible(cancelable).Alias for IO.delay.
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def async[A](k: ((Either[Throwable, A]) => Unit) => IO[Option[IO[Unit]]]): IO[A]
Suspends an asynchronous side effect in
IO.Suspends an asynchronous side effect in
IO.The given function
kwill be invoked during evaluation of theIOto "schedule" the asynchronous callback, where the callback of typeEither[Throwable, A] => Unitis the parameter passed to that function. Only the first invocation of the callback will be effective! All subsequent invocations will be silently dropped.The process of registering the callback itself is suspended in
IO(the outerIOofIO[Option[IO[Unit]]]).The effect returns
Option[IO[Unit]]which is an optional finalizer to be run in the event that the fiber runningasync(k)is canceled.For example, here is a simplified version of
IO.fromCompletableFuture:def fromCompletableFuture[A](fut: IO[CompletableFuture[A]]): IO[A] = { fut.flatMap { cf => IO.async { cb => IO { //Invoke the callback with the result of the completable future val stage = cf.handle[Unit] { case (a, null) => cb(Right(a)) case (_, e) => cb(Left(e)) } //Cancel the completable future if the fiber is canceled Some(IO(stage.cancel(false)).void) } } } }
- Note
asyncis always uncancelable during its registration. The created effect will be uncancelable during its execution if the registration callback provides no finalizer (i.e. evaluates toNone). If you need the created task to be cancelable, return a finalizer effect upon the registration. In a rare case when there's nothing to finalize, you can returnSome(IO.unit)for that.- See also
async_ for a simplified variant without a finalizer
asyncCheckAttempt for more generic version providing an optional immediate result of computation
- def asyncCheckAttempt[A](k: ((Either[Throwable, A]) => Unit) => IO[Either[Option[IO[Unit]], A]]): IO[A]
Suspends an asynchronous side effect with optional immediate result in
IO.Suspends an asynchronous side effect with optional immediate result in
IO.The given function
kwill be invoked during evaluation of theIOto:- check if result is already available;
- "schedule" the asynchronous callback, where the callback of type
Either[Throwable, A] \=> Unitis the parameter passed to that function. Only the first invocation of the callback will be effective! All subsequent invocations will be silently dropped.
The process of registering the callback itself is suspended in
IO(the outerIOofIO[Either[Option[IO[Unit]], A]]).The effect returns
Either[Option[IO[Unit]], A]where:- right side
Ais an immediate result of computation (callback invocation will be dropped); - left side
Option[IO[Unit]]is an optional finalizer to be run in the event that the fiber runningasyncCheckAttempt(k)is canceled.
For example, here is a simplified version of
IO.fromCompletableFuture:def fromCompletableFuture[A](fut: IO[CompletableFuture[A]]): IO[A] = { fut.flatMap { cf => IO.asyncCheckAttempt { cb => if (cf.isDone) { //Register immediately available result of the completable future or handle an error IO(cf.get) .map(Right(_)) .handleError { e => cb(Left(e)) Left(None) } } else { IO { //Invoke the callback with the result of the completable future val stage = cf.handle[Unit] { case (a, null) => cb(Right(a)) case (_, e) => cb(Left(e)) } //Cancel the completable future if the fiber is canceled Left(Some(IO(stage.cancel(false)).void)) } } } } }
Note that
asyncCheckAttemptis uncancelable during its registration.- See also
async for a simplified variant without an option for immediate result
- implicit def asyncForIO: kernel.Async[IO]
- def async_[A](k: ((Either[Throwable, A]) => Unit) => Unit): IO[A]
Suspends an asynchronous side effect in
IO.Suspends an asynchronous side effect in
IO.The given function
kwill be invoked during evaluation of theIOto "schedule" the asynchronous callback, where the callback is the parameter passed to that function. Only the first invocation of the callback will be effective! All subsequent invocations will be silently dropped.As a quick example, you can use this function to perform a parallel computation given an
ExecutorService:def fork[A](body: => A, exc: ExecutorService): IO[A] = IO async_ { cb => exc.execute(new Runnable { def run() = try cb(Right(body)) catch { case t if NonFatal(t) => cb(Left(t)) } }) }
The
forkfunction will do exactly what it sounds like: take a thunk and anExecutorServiceand run that thunk on the thread pool. Or rather, it will produce anIOwhich will do those things when run; it does *not* schedule the thunk until the resultingIOis run! Note that there is no thread blocking in this implementation; the resultingIOencapsulates the callback in a pure and monadic fashion without using threads.This function can be thought of as a safer, lexically-constrained version of
Promise, whereIOis like a safer, lazy version ofFuture.- Note
async_is uncancelable during both its registration and execution. If you need an asyncronous effect to be cancelable, consider usingasyncinstead.- See also
async for more generic version providing a finalizer
asyncCheckAttempt for more generic version providing an optional immediate result of computation and a finalizer
- def blocking[A](thunk: => A): IO[A]
Intended for thread blocking operations.
Intended for thread blocking operations.
blockingwill shift the execution of the blocking operation to a separate threadpool to avoid blocking on the main execution context. See the thread-model documentation for more information on why this is necessary. Note that the created effect will be uncancelable; if you need cancelation then you should use interruptible[A](thunk:=>A):* or interruptibleMany.IO.blocking(scala.io.Source.fromFile("path").mkString)- thunk
The side effect which is to be suspended in
IOand evaluated on a blocking execution context Implements cats.effect.kernel.Sync.blocking.
- Definition Classes
- IOCompanionPlatform
- def both[A, B](left: IO[A], right: IO[B]): IO[(A, B)]
- def bothOutcome[A, B](left: IO[A], right: IO[B]): IO[(OutcomeIO[A], OutcomeIO[B])]
- def bracketFull[A, B](acquire: (Poll[IO]) => IO[A])(use: (A) => IO[B])(release: (A, OutcomeIO[B]) => IO[Unit]): IO[B]
- def canceled: IO[Unit]
An effect that requests self-cancelation on the current fiber.
An effect that requests self-cancelation on the current fiber.
canceledhas a return type ofIO[Unit]instead ofIO[Nothing]due to execution continuing in a masked region. In the following example, the fiber requests self-cancelation in a masked region, so cancelation is suppressed until the fiber is completely unmasked.fawill run butfbwill not. Ifcanceledhad a return type ofIO[Nothing], then it would not be possible to continue execution tofa(there would be noNothingvalue to pass to theflatMap).IO.uncancelable { _ => IO.canceled *> fa } *> fb - implicit final def catsSyntaxParallelFlatSequence1[T[_], A](tioa: T[IO[T[A]]]): ParallelFlatSequenceOps1[T, IO, A]
- implicit final def catsSyntaxParallelSequence1[T[_], A](toia: T[IO[A]]): ParallelSequenceOps1[T, IO, A]
- implicit final def catsSyntaxParallelSequenceFilter[T[_], A](x: T[IO[Option[A]]]): ParallelSequenceFilterOps[T, IO, A]
- implicit final def catsSyntaxParallelSequence_[T[_], A](tioa: T[IO[A]]): ParallelSequence_Ops[T, IO, A]
- implicit final def catsSyntaxParallelUnorderedFlatSequence[T[_], A](tiota: T[IO[T[A]]]): ParallelUnorderedFlatSequenceOps[T, IO, A]
- implicit final def catsSyntaxParallelUnorderedSequence[T[_], A](tioa: T[IO[A]]): ParallelUnorderedSequenceOps[T, IO, A]
- implicit def catsSyntaxTuple10Parallel[M[_], A0, A1, A2, A3, A4, A5, A6, A7, A8, A9](t10: (M[A0], M[A1], M[A2], M[A3], M[A4], M[A5], M[A6], M[A7], M[A8], M[A9])): Tuple10ParallelOps[M, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9]
- Definition Classes
- TupleParallelSyntax
- implicit def catsSyntaxTuple11Parallel[M[_], A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10](t11: (M[A0], M[A1], M[A2], M[A3], M[A4], M[A5], M[A6], M[A7], M[A8], M[A9], M[A10])): Tuple11ParallelOps[M, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10]
- Definition Classes
- TupleParallelSyntax
- implicit def catsSyntaxTuple12Parallel[M[_], A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11](t12: (M[A0], M[A1], M[A2], M[A3], M[A4], M[A5], M[A6], M[A7], M[A8], M[A9], M[A10], M[A11])): Tuple12ParallelOps[M, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11]
- Definition Classes
- TupleParallelSyntax
- implicit def catsSyntaxTuple13Parallel[M[_], A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12](t13: (M[A0], M[A1], M[A2], M[A3], M[A4], M[A5], M[A6], M[A7], M[A8], M[A9], M[A10], M[A11], M[A12])): Tuple13ParallelOps[M, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12]
- Definition Classes
- TupleParallelSyntax
- implicit def catsSyntaxTuple14Parallel[M[_], A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13](t14: (M[A0], M[A1], M[A2], M[A3], M[A4], M[A5], M[A6], M[A7], M[A8], M[A9], M[A10], M[A11], M[A12], M[A13])): Tuple14ParallelOps[M, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13]
- Definition Classes
- TupleParallelSyntax
- implicit def catsSyntaxTuple15Parallel[M[_], A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14](t15: (M[A0], M[A1], M[A2], M[A3], M[A4], M[A5], M[A6], M[A7], M[A8], M[A9], M[A10], M[A11], M[A12], M[A13], M[A14])): Tuple15ParallelOps[M, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14]
- Definition Classes
- TupleParallelSyntax
- implicit def catsSyntaxTuple16Parallel[M[_], A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15](t16: (M[A0], M[A1], M[A2], M[A3], M[A4], M[A5], M[A6], M[A7], M[A8], M[A9], M[A10], M[A11], M[A12], M[A13], M[A14], M[A15])): Tuple16ParallelOps[M, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15]
- Definition Classes
- TupleParallelSyntax
- implicit def catsSyntaxTuple17Parallel[M[_], A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16](t17: (M[A0], M[A1], M[A2], M[A3], M[A4], M[A5], M[A6], M[A7], M[A8], M[A9], M[A10], M[A11], M[A12], M[A13], M[A14], M[A15], M[A16])): Tuple17ParallelOps[M, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16]
- Definition Classes
- TupleParallelSyntax
- implicit def catsSyntaxTuple18Parallel[M[_], A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17](t18: (M[A0], M[A1], M[A2], M[A3], M[A4], M[A5], M[A6], M[A7], M[A8], M[A9], M[A10], M[A11], M[A12], M[A13], M[A14], M[A15], M[A16], M[A17])): Tuple18ParallelOps[M, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17]
- Definition Classes
- TupleParallelSyntax
- implicit def catsSyntaxTuple19Parallel[M[_], A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18](t19: (M[A0], M[A1], M[A2], M[A3], M[A4], M[A5], M[A6], M[A7], M[A8], M[A9], M[A10], M[A11], M[A12], M[A13], M[A14], M[A15], M[A16], M[A17], M[A18])): Tuple19ParallelOps[M, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18]
- Definition Classes
- TupleParallelSyntax
- implicit def catsSyntaxTuple1Parallel[M[_], A0](t1: (M[A0])): Tuple1ParallelOps[M, A0]
- Definition Classes
- TupleParallelSyntax
- implicit def catsSyntaxTuple20Parallel[M[_], A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19](t20: (M[A0], M[A1], M[A2], M[A3], M[A4], M[A5], M[A6], M[A7], M[A8], M[A9], M[A10], M[A11], M[A12], M[A13], M[A14], M[A15], M[A16], M[A17], M[A18], M[A19])): Tuple20ParallelOps[M, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19]
- Definition Classes
- TupleParallelSyntax
- implicit def catsSyntaxTuple21Parallel[M[_], A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20](t21: (M[A0], M[A1], M[A2], M[A3], M[A4], M[A5], M[A6], M[A7], M[A8], M[A9], M[A10], M[A11], M[A12], M[A13], M[A14], M[A15], M[A16], M[A17], M[A18], M[A19], M[A20])): Tuple21ParallelOps[M, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20]
- Definition Classes
- TupleParallelSyntax
- implicit def catsSyntaxTuple22Parallel[M[_], A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21](t22: (M[A0], M[A1], M[A2], M[A3], M[A4], M[A5], M[A6], M[A7], M[A8], M[A9], M[A10], M[A11], M[A12], M[A13], M[A14], M[A15], M[A16], M[A17], M[A18], M[A19], M[A20], M[A21])): Tuple22ParallelOps[M, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21]
- Definition Classes
- TupleParallelSyntax
- implicit def catsSyntaxTuple2Parallel[M[_], A0, A1](t2: (M[A0], M[A1])): Tuple2ParallelOps[M, A0, A1]
- Definition Classes
- TupleParallelSyntax
- implicit def catsSyntaxTuple3Parallel[M[_], A0, A1, A2](t3: (M[A0], M[A1], M[A2])): Tuple3ParallelOps[M, A0, A1, A2]
- Definition Classes
- TupleParallelSyntax
- implicit def catsSyntaxTuple4Parallel[M[_], A0, A1, A2, A3](t4: (M[A0], M[A1], M[A2], M[A3])): Tuple4ParallelOps[M, A0, A1, A2, A3]
- Definition Classes
- TupleParallelSyntax
- implicit def catsSyntaxTuple5Parallel[M[_], A0, A1, A2, A3, A4](t5: (M[A0], M[A1], M[A2], M[A3], M[A4])): Tuple5ParallelOps[M, A0, A1, A2, A3, A4]
- Definition Classes
- TupleParallelSyntax
- implicit def catsSyntaxTuple6Parallel[M[_], A0, A1, A2, A3, A4, A5](t6: (M[A0], M[A1], M[A2], M[A3], M[A4], M[A5])): Tuple6ParallelOps[M, A0, A1, A2, A3, A4, A5]
- Definition Classes
- TupleParallelSyntax
- implicit def catsSyntaxTuple7Parallel[M[_], A0, A1, A2, A3, A4, A5, A6](t7: (M[A0], M[A1], M[A2], M[A3], M[A4], M[A5], M[A6])): Tuple7ParallelOps[M, A0, A1, A2, A3, A4, A5, A6]
- Definition Classes
- TupleParallelSyntax
- implicit def catsSyntaxTuple8Parallel[M[_], A0, A1, A2, A3, A4, A5, A6, A7](t8: (M[A0], M[A1], M[A2], M[A3], M[A4], M[A5], M[A6], M[A7])): Tuple8ParallelOps[M, A0, A1, A2, A3, A4, A5, A6, A7]
- Definition Classes
- TupleParallelSyntax
- implicit def catsSyntaxTuple9Parallel[M[_], A0, A1, A2, A3, A4, A5, A6, A7, A8](t9: (M[A0], M[A1], M[A2], M[A3], M[A4], M[A5], M[A6], M[A7], M[A8])): Tuple9ParallelOps[M, A0, A1, A2, A3, A4, A5, A6, A7, A8]
- Definition Classes
- TupleParallelSyntax
- def cede: IO[Unit]
Introduces a fairness boundary that yields control back to the scheduler of the runtime system.
Introduces a fairness boundary that yields control back to the scheduler of the runtime system. This allows the carrier thread to resume execution of another waiting fiber.
This function is primarily useful when performing long-running computation that is outside of the monadic context. For example:
fa.map(data => expensiveWork(data))In the above, we're assuming that
expensiveWorkis a function which is entirely compute-bound but very long-running. A good rule of thumb is to consider a function "expensive" when its runtime is around three or more orders of magnitude higher than the overhead of themapfunction itself (which runs in around 5 nanoseconds on modern hardware). Thus, anyexpensiveWorkfunction which requires around 10 microseconds or longer to execute should be considered "long-running".The danger is that these types of long-running actions outside of the monadic context can result in degraded fairness properties. The solution is to add an explicit
cedeboth before and after the expensive operation:(fa <* IO.cede).map(data => expensiveWork(data)).guarantee(IO.cede)Note that extremely long-running
expensiveWorkfunctions can still cause fairness issues, even when used withcede. This problem is somewhat fundamental to the nature of scheduling such computation on carrier threads. Whenever possible, it is best to break apart any such functions into multiple pieces invoked independently (e.g. via chainedmapcalls) whenever the execution time exceeds five or six orders of magnitude beyond the overhead ofmapitself (around 1 millisecond on most hardware).This operation is not required in most applications, particularly those which are primarily I/O bound, as
IOitself will automatically introduce fairness boundaries without requiring user input. These automatic boundaries are controlled by the cats.effect.unsafe.IORuntimeConfig.autoYieldThreshold configuration parameter, which in turn may be adjusted by overriding IOApp.runtimeConfig. - def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- implicit def commutativeApplicativeForIOPar: CommutativeApplicative[Par]
- implicit val consoleForIO: Console[IO]
- def cont[K, R](body: Cont[IO, K, R]): IO[R]
This is a low-level API which is meant for implementors, please use
background,start,async, orDeferredinstead, depending on the use case - def defer[A](thunk: => IO[A]): IO[A]
Suspends a synchronous side effect which produces an
IOinIO.Suspends a synchronous side effect which produces an
IOinIO.This is useful for trampolining (i.e. when the side effect is conceptually the allocation of a stack frame). Any exceptions thrown by the side effect will be caught and sequenced into the
IO. - def deferred[A]: IO[Deferred[IO, A]]
- def delay[A](thunk: => A): IO[A]
Suspends a synchronous side effect in
IO.Suspends a synchronous side effect in
IO. Use IO.delay if your side effect is not thread-blocking; otherwise you should use IO.blocking (uncancelable) orIO.interruptible(cancelable).Any exceptions thrown by the effect will be caught and sequenced into the
IO. - implicit val envForIO: Env[IO]
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def eval[A](fa: Eval[A]): IO[A]
Lifts an
EvalintoIO.Lifts an
EvalintoIO.This function will preserve the evaluation semantics of any actions that are lifted into the pure
IO. EagerEvalinstances will be converted into thunk-lessIO(i.e. eagerIO), while lazy eval and memoized will be executed as such. - def executionContext: IO[ExecutionContext]
- def executor: IO[Executor]
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- def fromCompletableFuture[A](fut: IO[CompletableFuture[A]]): IO[A]
- Definition Classes
- IOCompanionPlatform
- def fromCompletionStage[A](completionStage: IO[CompletionStage[A]]): IO[A]
- Definition Classes
- IOCompanionPlatform
- def fromEither[A](e: Either[Throwable, A]): IO[A]
Lifts an
Either[Throwable, A]into theIO[A]context, raising the throwable if it exists. - def fromFuture[A](fut: IO[Future[A]]): IO[A]
Constructs an
IOwhich evaluates the givenFutureand produces the result (or failure).Constructs an
IOwhich evaluates the givenFutureand produces the result (or failure).Because
Futureeagerly evaluates, as well as because it memoizes, this function takes its parameter as anIO, which could be lazily evaluated. If this laziness is appropriately threaded back to the definition site of theFuture, it ensures that the computation is fully managed byIOand thus referentially transparent.Example:
// Lazy evaluation, equivalent with by-name params IO.fromFuture(IO(f)) // Eager evaluation, for pure futures IO.fromFuture(IO.pure(f))
Roughly speaking, the following identities hold:
IO.fromFuture(IO(f)).unsafeToFuture() === f // true-ish (except for memoization) IO.fromFuture(IO(ioa.unsafeToFuture())) === ioa // true
- See also
- def fromFutureCancelable[A](fut: IO[(Future[A], IO[Unit])]): IO[A]
Like fromFuture, but is cancelable via the provided finalizer.
- def fromOption[A](o: Option[A])(orElse: => Throwable): IO[A]
Lifts an
Option[A]into theIO[A]context, raising the throwable if the option is empty. - def fromTry[A](t: Try[A]): IO[A]
Lifts an
Try[A]into theIO[A]context, raising the throwable if it exists. - final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def interruptible[A](thunk: => A): IO[A]
Like blocking but will attempt to abort the blocking operation using thread interrupts in the event of cancelation.
Like blocking but will attempt to abort the blocking operation using thread interrupts in the event of cancelation. The interrupt will be attempted only once.
Note the following tradeoffs:
- this has slightly more overhead than blocking due to the machinery necessary for the interrupt coordination,
- thread interrupts are very often poorly considered by Java (and Scala!) library authors, and it is possible for interrupts to result in resource leaks or invalid states. It is important to be certain that this will not be the case before using this mechanism.
- thunk
The side effect which is to be suspended in
IOand evaluated on a blocking execution context Implements cats.effect.kernel.Sync.interruptible[A](thunk:=>A):*
- Definition Classes
- IOCompanionPlatform
- def interruptibleMany[A](thunk: => A): IO[A]
Like blocking but will attempt to abort the blocking operation using thread interrupts in the event of cancelation.
Like blocking but will attempt to abort the blocking operation using thread interrupts in the event of cancelation. The interrupt will be attempted repeatedly until the blocking operation completes or exits.
Note the following tradeoffs:
- this has slightly more overhead than blocking due to the machinery necessary for the interrupt coordination,
- thread interrupts are very often poorly considered by Java (and Scala!) library authors, and it is possible for interrupts to result in resource leaks or invalid states. It is important to be certain that this will not be the case before using this mechanism.
- thunk
The side effect which is to be suspended in
IOand evaluated on a blocking execution context Implements cats.effect.kernel.Sync!.interruptibleMany
- Definition Classes
- IOCompanionPlatform
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def local[E](e: E): IO[mtl.Local[IO, E]]
- implicit def monoidForIO[A](implicit arg0: Monoid[A]): Monoid[IO[A]]
- def monotonic: IO[FiniteDuration]
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def never[A]: IO[A]
A non-terminating
IO, alias forasync(_ => ()). - def none[A]: IO[Option[A]]
An IO that contains an empty Option.
An IO that contains an empty Option.
- See also
some for the non-empty Option variant
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- def parReplicateAN[A](n: Int)(replicas: Int, ioa: IO[A]): IO[List[A]]
Like
Parallel.parReplicateA, but limits the degree of parallelism. - def parSequence[T[_], A](tioa: T[IO[A]])(implicit arg0: Traverse[T]): IO[T[A]]
Like
Parallel.parSequence - def parSequenceN[T[_], A](n: Int)(tioa: T[IO[A]])(implicit arg0: Traverse[T]): IO[T[A]]
Like
Parallel.parSequence, but limits the degree of parallelism. - def parSequenceN_[T[_], A](n: Int)(tma: T[IO[A]])(implicit arg0: Foldable[T]): IO[Unit]
Like
Parallel.parSequence_, but limits the degree of parallelism. - def parSequence_[T[_], A](tioa: T[IO[A]])(implicit arg0: Foldable[T]): IO[Unit]
Like
Parallel.parSequence_ - def parTraverse[T[_], A, B](ta: T[A])(f: (A) => IO[B])(implicit arg0: Traverse[T]): IO[T[B]]
Like
Parallel.parTraverse - def parTraverseN[T[_], A, B](n: Int)(ta: T[A])(f: (A) => IO[B])(implicit arg0: Traverse[T]): IO[T[B]]
Like
Parallel.parTraverse, but limits the degree of parallelism. - def parTraverseN_[T[_], A, B](n: Int)(ta: T[A])(f: (A) => IO[B])(implicit arg0: Foldable[T]): IO[Unit]
Like
Parallel.parTraverse_, but limits the degree of parallelism. - def parTraverse_[T[_], A, B](ta: T[A])(f: (A) => IO[B])(implicit arg0: Foldable[T]): IO[Unit]
Like
Parallel.parTraverse_ - implicit def parallelForIO: Aux[IO, Par]
- def pollers: IO[List[Any]]
- def print[A](a: A)(implicit S: Show[A] = Show.fromToString[A]): IO[Unit]
Prints a value to the standard output using the implicit
cats.Showinstance.Prints a value to the standard output using the implicit
cats.Showinstance.- a
value to be printed to the standard output
- See also
cats.effect.std.Consolefor more standard input, output and error operations
- def println[A](a: A)(implicit S: Show[A] = Show.fromToString[A]): IO[Unit]
Prints a value to the standard output followed by a new line using the implicit
cats.Showinstance.Prints a value to the standard output followed by a new line using the implicit
cats.Showinstance.- a
value to be printed to the standard output
- See also
cats.effect.std.Consolefor more standard input, output and error operations
- def pure[A](value: A): IO[A]
Lifts a pure value into
IO.Lifts a pure value into
IO.This should only be used if the value in question has "already" been computed! In other words, something like
IO.pure(readLine)is most definitely not the right thing to do! However,IO.pure(42)is correct and will be more efficient (when evaluated) thanIO(42), due to avoiding the allocation of extra thunks. - def race[A, B](left: IO[A], right: IO[B]): IO[Either[A, B]]
Run two IO tasks concurrently, and return the first to finish, either in success or error.
Run two IO tasks concurrently, and return the first to finish, either in success or error. The loser of the race is canceled.
The two tasks are executed in parallel, the winner being the first that signals a result.
As an example see IO.timeout and IO.timeoutTo
Also see racePair for a version that does not cancel the loser automatically on successful results.
- left
is the "left" task participating in the race
- right
is the "right" task participating in the race
- def racePair[A, B](left: IO[A], right: IO[B]): IO[Either[(OutcomeIO[A], FiberIO[B]), (FiberIO[A], OutcomeIO[B])]]
Run two IO tasks concurrently, and returns a pair containing both the winner's successful value and the loser represented as a still-unfinished task.
Run two IO tasks concurrently, and returns a pair containing both the winner's successful value and the loser represented as a still-unfinished task.
On usage the user has the option of canceling the losing task, this being equivalent with plain race:
val ioA: IO[A] = ??? val ioB: IO[B] = ??? IO.racePair(ioA, ioB).flatMap { case Left((a, fiberB)) => fiberB.cancel.as(a) case Right((fiberA, b)) => fiberA.cancel.as(b) }
See race for a simpler version that cancels the loser immediately.
- left
is the "left" task participating in the race
- right
is the "right" task participating in the race
- def raiseError[A](t: Throwable): IO[A]
Constructs an
IOwhich sequences the specified exception.Constructs an
IOwhich sequences the specified exception.If this
IOis run usingunsafeRunSyncorunsafeRunTimed, the exception will be thrown. This exception can be "caught" (or rather, materialized into value-space) using theattemptmethod.- See also
- def raiseUnless(cond: Boolean)(e: => Throwable): IO[Unit]
Returns
raiseErrorwhencondis false, otherwise IO.unitReturns
raiseErrorwhencondis false, otherwise IO.unitval tooMany = 5 val x: Int = ??? IO.raiseUnless(x < tooMany)(new IllegalArgumentException("Too many"))
Example: - def raiseWhen(cond: Boolean)(e: => Throwable): IO[Unit]
Returns
raiseErrorwhen thecondis true, otherwiseIO.unitReturns
raiseErrorwhen thecondis true, otherwiseIO.unitval tooMany = 5 val x: Int = ??? IO.raiseWhen(x >= tooMany)(new IllegalArgumentException("Too many"))
Example: - def randomUUID: IO[UUID]
- returns
a randomly-generated UUID This is equivalent to
UUIDGen[IO].randomUUID, just provided as a method for convenience
- def readLine: IO[String]
Reads a line as a string from the standard input using the platform's default charset, as per
java.nio.charset.Charset.defaultCharset().Reads a line as a string from the standard input using the platform's default charset, as per
java.nio.charset.Charset.defaultCharset().The effect can raise a
java.io.EOFExceptionif no input has been consumed before the EOF is observed. This should never happen with the standard input, unless it has been replaced with a finitejava.io.InputStreamthroughjava.lang.System#setInor similar.- returns
an IO effect that describes reading the user's input from the standard input as a string
- Definition Classes
- IOCompanionPlatform
- See also
cats.effect.std.Console#readLineWithCharsetfor reading using a customjava.nio.charset.Charset
- def realTime: IO[FiniteDuration]
- def realTimeInstant: IO[Instant]
- Definition Classes
- IOCompanionPlatform
- def ref[A](a: A): IO[Ref[IO, A]]
- implicit lazy val secureRandom: SecureRandom[IO]
- implicit def semigroupForIO[A](implicit arg0: Semigroup[A]): Semigroup[IO[A]]
- Definition Classes
- IOLowPriorityImplicits
- implicit val semigroupKForIO: SemigroupK[IO]
- implicit def showForIO[A](implicit arg0: Show[A]): Show[IO[A]]
- implicit def showForIONoPure[A]: Show[IO[A]]
- Definition Classes
- IOLowPriorityImplicits
- def sleep(finiteDelay: FiniteDuration): IO[Unit]
- def sleep(delay: Duration): IO[Unit]
Creates an asynchronous task that on evaluation sleeps for the specified duration, emitting a notification on completion.
Creates an asynchronous task that on evaluation sleeps for the specified duration, emitting a notification on completion.
This is the pure, non-blocking equivalent to:
Thread.sleep(JVM)ScheduledExecutorService.schedule(JVM)setTimeout(JavaScript)
You can combine it with
flatMapto create delayed tasks:val timeout = IO.sleep(10.seconds).flatMap { _ => IO.raiseError(new TimeoutException) }
The created task is cancelable and so it can be used safely in race conditions without resource leakage.
- delay
the time span to wait before emitting the tick
- returns
a new asynchronous and cancelable
IOthat will sleep for the specified duration and then finally emit a tick
- def some[A](a: A): IO[Option[A]]
An IO that contains some Option of the given value.
An IO that contains some Option of the given value.
- See also
none for the empty Option variant
- def stub: IO[Nothing]
- def suspend[A](hint: Type)(thunk: => A): IO[A]
- Definition Classes
- IOCompanionPlatform
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- implicit val systemPropertiesForIO: SystemProperties[IO]
- def toString(): String
- Definition Classes
- AnyRef → Any
- def trace: IO[Trace]
- def traverse[T[_], A, B](ta: T[A])(f: (A) => IO[B])(implicit arg0: Traverse[T]): IO[T[B]]
- def traverse_[T[_], A, B](ta: T[A])(f: (A) => IO[B])(implicit arg0: Foldable[T]): IO[Unit]
- def uncancelable[A](body: (Poll[IO]) => IO[A]): IO[A]
- def unique: IO[Token]
- def unit: IO[Unit]
Alias for
IO.pure(()). - def unlessA(cond: Boolean)(action: => IO[Unit]): IO[Unit]
Returns the given argument if
condis false, otherwiseIO.UnitReturns the given argument if
condis false, otherwiseIO.Unit- See also
IO.whenA for the inverse
IO.raiseWhen for conditionally raising an error
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- 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()
- def whenA(cond: Boolean)(action: => IO[Unit]): IO[Unit]
Returns the given argument if
condis true, otherwiseIO.UnitReturns the given argument if
condis true, otherwiseIO.Unit- See also
IO.unlessA for the inverse
IO.raiseWhen for conditionally raising an error