Resource
- Companion
- class
trait Sum
trait Mirror
trait ResourcePlatform
class ResourceInstances
class ResourceInstances0
class Object
trait Matchable
class Any
Type members
Classlikes
final case class Allocate[F <: ([_$39] =>> Any), A](resource: Poll[F] => F[(A, ExitCase => F[Unit])]) extends Resource[F, A]
Resource
data constructor that wraps an effect allocating a resource,along with its finalizers.
final case class Bind[F <: ([_$40] =>> Any), S, +A](source: Resource[F, S], fs: S => Resource[F, A]) extends Resource[F, A]
Resource
data constructor that encodes the flatMap
operation.Types
Newtype encoding for a
capable of doing parallel processing in
for implementing
Resource
datatype that has a cats.Applicative
capable of doing parallel processing in
ap
and map2
, neededfor implementing
cats.Parallel
.Helpers are provided for converting back and forth in
for wrapping any
Par.apply
for wrapping any
IO
value and Par.unwrap
for unwrapping.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.
alexknvl/newtypes.
Alexander Konovalov, chosen because it's devoid of boxing issues and
a good choice until opaque types will land in Scala.
alexknvl/newtypes.
Value members
Methods
Creates a resource from an allocating effect.
- Type Params
- A
-
the type of the resource
- F
-
the effect type in which the resource is acquired and released
- Value Params
- resource
-
an effect that returns a tuple of a resource and
an effect to release it
- See also
- make for a version that separates the needed resource
with its finalizer tuple in two parameters
Creates a resource from an allocating effect, with a finalizer
that is able to distinguish between exit cases.
that is able to distinguish between exit cases.
- Type Params
- A
-
the type of the resource
- F
-
the effect type in which the resource is acquired and released
- Value Params
- resource
-
an effect that returns a tuple of a resource and
an effectful function to release it
- See also
- makeCase for a version that separates the needed resource
with its finalizer tuple in two parameters
def applyFull[F <: ([_$22] =>> Any), A](resource: Poll[F] => F[(A, ExitCase => F[Unit])]): Resource[F, A]
Creates a resource from an allocating effect, with a finalizer
that is able to distinguish between exit cases.
that is able to distinguish between exit cases.
The action takes a
which is most often useful when acquiring lock-like structure: it
should be possible to interrupt a fiber waiting on a lock, but if
it does get acquired, release need to be guaranteed.
Poll[F]
to allow for interruptible acquires,which is most often useful when acquiring lock-like structure: it
should be possible to interrupt a fiber waiting on a lock, but if
it does get acquired, release need to be guaranteed.
Note that in this case the acquire action should know how to cleanup
after itself in case it gets canceled, since Resource will only
guarantee release when acquire succeeds and fails (and when the
actions in
after itself in case it gets canceled, since Resource will only
guarantee release when acquire succeeds and fails (and when the
actions in
use
or flatMap
fail, succeed, or get canceled)TODO make sure this api, which is more general than makeFull, doesn't allow
for interruptible releases
for interruptible releases
- Type Params
- A
-
the type of the resource
- F
-
the effect type in which the resource is acquired and released
- Value Params
- resource
-
an effect that returns a tuple of a resource and
an effectful function to release it, where acquisition can
potentially be interrupted
- See also
- makeFull for a version that separates the needed resource
with its finalizer tuple in two parameters
def make[F <: ([_$24] =>> Any), A](acquire: F[A])(release: A => F[Unit])(F: Functor[F]): Resource[F, A]
Creates a resource from an acquiring effect and a release function.
- Type Params
- A
-
the type of the resource
- F
-
the effect type in which the resource is acquired and released
- Value Params
- acquire
-
an effect to acquire a resource
- release
-
a function to effectfully release the resource returned by
acquire
def makeCase[F <: ([_$25] =>> Any), A](acquire: F[A])(release: (A, ExitCase) => F[Unit])(F: Functor[F]): Resource[F, A]
Creates a resource from an acquiring effect and a release function that can
discriminate between different exit cases.
discriminate between different exit cases.
- Type Params
- A
-
the type of the resource
- F
-
the effect type in which the resource is acquired and released
- Value Params
- acquire
-
a function to effectfully acquire a resource
- release
-
a function to effectfully release the resource returned by
acquire
def makeFull[F <: ([_$26] =>> Any), A](acquire: Poll[F] => F[A])(release: A => F[Unit])(F: Functor[F]): Resource[F, A]
Creates a resource from an acquiring effect and a release
function that can discriminate between different exit cases.
function that can discriminate between different exit cases.
The acquiring effect takes a
acquires, which is most often useful when acquiring lock-like
structures: it should be possible to interrupt a fiber waiting on
a lock, but if it does get acquired, release need to be
guaranteed.
Poll[F]
to allow for interruptibleacquires, which is most often useful when acquiring lock-like
structures: it should be possible to interrupt a fiber waiting on
a lock, but if it does get acquired, release need to be
guaranteed.
Note that in this case the acquire action should know how to cleanup
after itself in case it gets canceled, since Resource will only
guarantee release when acquire succeeds and fails (and when the
actions in
after itself in case it gets canceled, since Resource will only
guarantee release when acquire succeeds and fails (and when the
actions in
use
or flatMap
fail, succeed, or get canceled)- Type Params
- A
-
the type of the resource
- F
-
the effect type in which the resource is acquired and released
- Value Params
- acquire
-
an effect to acquire a resource, possibly interruptibly
- release
-
a function to effectfully release the resource returned by
acquire
def makeCaseFull[F <: ([_$28] =>> Any), A](acquire: Poll[F] => F[A])(release: (A, ExitCase) => F[Unit])(F: Functor[F]): Resource[F, A]
Creates a resource from an acquiring effect and a release
function that can discriminate between different exit cases.
function that can discriminate between different exit cases.
The acquiring effect takes a
acquires, which is most often useful when acquiring lock-like
structures: it should be possible to interrupt a fiber waiting on
a lock, but if it does get acquired, release need to be
guaranteed.
Poll[F]
to allow for interruptibleacquires, which is most often useful when acquiring lock-like
structures: it should be possible to interrupt a fiber waiting on
a lock, but if it does get acquired, release need to be
guaranteed.
Note that in this case the acquire action should know how to cleanup
after itself in case it gets canceled, since Resource will only
guarantee release when acquire succeeds and fails (and when the
actions in
after itself in case it gets canceled, since Resource will only
guarantee release when acquire succeeds and fails (and when the
actions in
use
or flatMap
fail, succeed, or get canceled)- Type Params
- A
-
the type of the resource
- F
-
the effect type in which the resource is acquired and released
- Value Params
- acquire
-
an effect to acquire a resource, possibly interruptibly
- release
-
a function to effectfully release the resource returned by
acquire
Lifts a pure value into a resource. The resource has a no-op release.
- Value Params
- a
-
the value to lift into a resource
@deprecated("please use `eval` instead.", since = "3.0")
Lifts an applicative into a resource. The resource has a no-op release.
Preserves interruptibility of
Preserves interruptibility of
fa
.- Value Params
- fa
-
the value to lift into a resource
def onFinalize[F <: ([_$33] =>> Any)](release: F[Unit])(evidence$1: Applicative[F]): Resource[F, Unit]
Lifts a finalizer into a resource. The resource has a no-op allocation.
def onFinalizeCase[F <: ([_$34] =>> Any)](release: ExitCase => F[Unit])(evidence$2: Applicative[F]): Resource[F, Unit]
Creates a resource that allocates immediately without any effects,
but calls
but calls
release
when closing, providing the the usage completed with. def fromAutoCloseable[F <: ([_$38] =>> Any), A <: AutoCloseable](acquire: F[A])(F: Sync[F]): Resource[F, A]
In most real world cases, implementors of AutoCloseable are
blocking as well, so the close action runs in the blocking
context.
blocking as well, so the close action runs in the blocking
context.
Example:
{{{
import cats.effect._
import scala.io.Source
{{{
import cats.effect._
import scala.io.Source
def reader[F[_]
](data: String)(implicit F: Sync[F]
): Resource[F, Source]
=
Resource.fromAutoCloseable(F.blocking {
Source.fromString(data)
})
}}}
Resource.fromAutoCloseable(F.blocking {
Source.fromString(data)
})
}}}
- Type Params
- A
-
the type of the autocloseable resource
- F
-
the type of the effect
- Value Params
- F
-
the effect type in which the resource was acquired and will be released
- acquire
-
The effect with the resource to acquire.
- Returns
-
a Resource that will automatically close after use
Inherited methods
def fromDestroyable[F <: ([_$1] =>> Any), A <: Destroyable](acquire: F[A])(F: Sync[F]): Resource[F, A]
Example:
{{{
import java.security.KeyStore.PasswordProtection
import cats.effect._
import cats.syntax.all._
{{{
import java.security.KeyStore.PasswordProtection
import cats.effect._
import cats.syntax.all._
def passwordProtection[F[_]
](getPassword: F[Array[Char]
])(implicit F: Sync[F]
): Resource[F, PasswordProtection]
=
Resource.fromDestroyable(
getPassword.map(new PasswordProtection(_))
)
}}}
Resource.fromDestroyable(
getPassword.map(new PasswordProtection(_))
)
}}}
- Type Params
- A
-
the type of the destroyable resource
- F
-
the type of the effect
- Value Params
- F
-
the effect type in which the resource was acquired and will be released
- acquire
-
The effect with the resource to acquire.
- Returns
-
a Resource that will automatically destroy after use
- Inhertied from
- ResourcePlatform
Implicits
Inherited implicits
implicit def catsEffectCommutativeApplicativeForResourcePar[F <: ([_$55] =>> Any)](F: Concurrent[F]): CommutativeApplicative[[_$56] =>> Type[F, _$56]]
- Inhertied from
- ResourceInstances
implicit def catsEffectParallelForResource[F0 <: ([_$57] =>> Any)](evidence$3: Concurrent[F0]): Aux[[_$58] =>> Resource[F0, _$58], [_$59] =>> Type[F0, _$59]]
- Inhertied from
- ResourceInstances
implicit def catsEffectMonadForResource[F <: ([_$60] =>> Any)](F0: Monad[F]): Monad[[_$61] =>> Resource[F, _$61]]
- Inhertied from
- ResourceInstances0
implicit def catsEffectMonoidForResource[F <: ([_$54] =>> Any), A](F0: Monad[F], A0: Monoid[A]): Monoid[Resource[F, A]]
- Inhertied from
- ResourceInstances
implicit def catsEffectSemigroupForResource[F <: ([_$62] =>> Any), A](F0: Monad[F], A0: Semigroup[A]): ResourceSemigroup[F, A]
- Inhertied from
- ResourceInstances0
implicit def catsEffectSemigroupKForResource[F <: ([_$63] =>> Any), A](F0: MonadCancel[F, Throwable], K0: SemigroupK[F], G0: Make[F]): ResourceSemigroupK[F]
- Inhertied from
- ResourceInstances0
implicit def catsEffectMonadErrorForResource[F <: ([_$52] =>> Any), E](F0: MonadError[F, E]): MonadError[[_$53] =>> Resource[F, _$53], E]
- Inhertied from
- ResourceInstances