package effect
- Alphabetic
- By Inheritance
- effect
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
- type Async[F[_]] = effect.kernel.Async[F]
- type Clock[F[_]] = effect.kernel.Clock[F]
- type Concurrent[F[_], E] = effect.kernel.Concurrent[F, E]
- type ConcurrentThrow[F[_]] = effect.kernel.Concurrent[F, Throwable]
- type Effect[F[_]] = effect.kernel.Effect[F]
- type Fiber[F[_], E, A] = effect.kernel.Fiber[F, E, A]
- type FiberIO[A] = effect.kernel.Fiber[IO, Throwable, A]
- sealed abstract class IO[+A] extends IOPlatform[A]
- trait IOApp extends AnyRef
- trait LiftIO[F[_]] extends AnyRef
- type Outcome[F[_], E, A] = effect.kernel.Outcome[F, E, A]
- type OutcomeIO[A] = effect.kernel.Outcome[IO, Throwable, A]
- type ParallelF[F[_], A] = T[F, A]
- type Poll[F[_]] = effect.kernel.Poll[F]
-
sealed abstract
class
Resource[+F[_], +A] extends AnyRef
The
Resource
is a data structure that captures the effectful allocation of a resource, along with its finalizer.The
Resource
is a data structure that captures the effectful allocation of a resource, along with its finalizer.This can be used to wrap expensive resources. Example:
def open(file: File): Resource[IO, BufferedReader] = Resource(IO { val in = new BufferedReader(new FileReader(file)) (in, IO(in.close())) })
Usage is done via use and note that resource usage nests, because its implementation is specified in terms of Bracket:
open(file1).use { in1 => open(file2).use { in2 => readFiles(in1, in2) } }
Resource
forms aMonadError
on the resource type when the effect type has acats.MonadError
instance. Nested resources are released in reverse order of acquisition. Outer resources are released even if an inner use or release fails.def mkResource(s: String) = { val acquire = IO(println(s"Acquiring $$s")) *> IO.pure(s) def release(s: String) = IO(println(s"Releasing $$s")) Resource.make(acquire)(release) } val r = for { outer <- mkResource("outer") inner <- mkResource("inner") } yield (outer, inner) r.use { case (a, b) => IO(println(s"Using $$a and $$b")) }
On evaluation the above prints:
Acquiring outer Acquiring inner Using outer and inner Releasing inner Releasing outer
A
Resource
is nothing more than a data structure, an ADT, described by the following node types and that can be interpreted if needed:Normally users don't need to care about these node types, unless conversions from
Resource
into something else is needed (e.g. conversion fromResource
into a streaming data type).- F
the effect type in which the resource is allocated and released
- A
the type of resource
- type Sync[F[_]] = effect.kernel.Sync[F]
- type SyncEffect[F[_]] = effect.kernel.SyncEffect[F]
-
sealed abstract
class
SyncIO[+A] extends AnyRef
A pure abstraction representing the intention to perform a side effect, where the result of that side effect is obtained synchronously.
A pure abstraction representing the intention to perform a side effect, where the result of that side effect is obtained synchronously.
SyncIO
is similar to IO, but does not support asynchronous computations. Consequently, aSyncIO
can be run synchronously to obtain a result viaunsafeRunSync
. This is unlikeIO#unsafeRunSync
, which cannot be safely called in general -- doing so on the JVM blocks the calling thread while the async part of the computation is run and doing so on Scala.js throws an exception upon encountering an async boundary. - type Temporal[F[_], E] = effect.kernel.Temporal[F, E]
- type TemporalThrow[F[_]] = effect.kernel.Temporal[F, Throwable]
- trait UnsafeTimer extends AnyRef
Value Members
- val Async: effect.kernel.Async.type
- val Clock: effect.kernel.Clock.type
- val Concurrent: effect.kernel.Concurrent.type
- val Effect: effect.kernel.Effect.type
- val Outcome: effect.kernel.Outcome.type
- val ParallelF: effect.kernel.Par.ParallelF.type
- val Sync: effect.kernel.Sync.type
- val SyncEffect: effect.kernel.SyncEffect.type
- val Temporal: effect.kernel.Temporal.type
- object IO extends IOCompanionPlatform with IOLowPriorityImplicits
- object LiftIO
- object Resource extends ResourceInstances with ResourcePlatform
- object SyncIO extends SyncIOLowPriorityImplicits
- object UnsafeTimer