object Resource extends ResourceFOInstances0 with ResourceHOInstances0 with ResourcePlatform
- Source
- Resource.scala
- Alphabetic
- By Inheritance
- Resource
- ResourcePlatform
- Serializable
- ResourceHOInstances0
- ResourceHOInstances1
- ResourceHOInstances2
- ResourceHOInstances3
- ResourceHOInstances4
- ResourceHOInstances5
- ResourceFOInstances0
- ResourceFOInstances1
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
- final case class Allocate[F[_], A](resource: (Poll[F]) => F[(A, (ExitCase) => F[Unit])]) extends Resource[F, A] with Product with Serializable
Resource
data constructor that wraps an effect allocating a resource, along with its finalizers. - final case class Bind[F[_], S, +A](source: Resource[F, S], fs: (S) => Resource[F, A]) extends Resource[F, A] with Product with Serializable
Resource
data constructor that encodes theflatMap
operation. - final case class Eval[F[_], A](fa: F[A]) extends Resource[F, A] with Product with Serializable
- sealed trait ExitCase extends Product with Serializable
Type for signaling the exit condition of an effectful computation, that may either succeed, fail with an error or get canceled.
- implicit final class NestedSyntax[F[_], A] extends AnyVal
- type Par[F[_], A] = T[[β$19$]Resource[F, β$19$], A]
- final case class Pure[F[_], +A](a: A) extends Resource[F, A] with Product with Serializable
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
- def apply[F[_], A](resource: F[(A, F[Unit])])(implicit F: Functor[F]): Resource[F, A]
Creates a resource from an allocating effect.
Creates a resource from an allocating effect.
- F
the effect type in which the resource is acquired and released
- A
the type of the resource
- 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
- def applyCase[F[_], A](resource: 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.
Creates a resource from an allocating effect, with a finalizer that is able to distinguish between exit cases.
- F
the effect type in which the resource is acquired and released
- A
the type of the resource
- 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[_], 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.
Creates a resource from an allocating effect, with a finalizer that is able to distinguish between exit cases.
The action takes a
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 when the actions in
use
orflatMap
fail, succeed, or get canceled)TODO make sure this api, which is more general than makeFull, doesn't allow for interruptible releases
- F
the effect type in which the resource is acquired and released
- A
the type of the resource
- 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
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def both[F[_], A, B](rfa: Resource[F, A], rfb: Resource[F, B])(implicit arg0: Concurrent[F]): Resource[F, (A, B)]
Allocates two resources concurrently, and combines their results in a tuple.
- def canceled[F[_]](implicit F: MonadCancel[F, _]): Resource[F, Unit]
- implicit def catsEffectAsyncForResource[F[_]](implicit F0: Async[F]): Async[[β$25$]Resource[F, β$25$]]
- Definition Classes
- ResourceHOInstances0
- implicit def catsEffectClockForResource[F[_]](implicit F0: Clock[F], FA: Applicative[[β$29$]Resource[F, β$29$]]): Clock[[β$30$]Resource[F, β$30$]]
- Definition Classes
- ResourceHOInstances2
- implicit def catsEffectConcurrentForResource[F[_]](implicit F0: Concurrent[F]): Concurrent[[β$28$]Resource[F, β$28$]]
- Definition Classes
- ResourceHOInstances2
- implicit final def catsEffectDeferForResource[F[_]]: Defer[[β$31$]Resource[F, β$31$]]
- Definition Classes
- ResourceHOInstances2
- implicit def catsEffectMonadCancelForResource[F[_]](implicit F0: MonadCancel[F, Throwable]): MonadCancel[[β$32$]Resource[F, β$32$], Throwable]
- Definition Classes
- ResourceHOInstances3
- implicit def catsEffectMonadErrorForResource[F[_], E](implicit F0: MonadError[F, E]): MonadError[[β$33$]Resource[F, β$33$], E]
- Definition Classes
- ResourceHOInstances4
- implicit def catsEffectMonadForResource[F[_]]: Monad[[β$34$]Resource[F, β$34$]]
- Definition Classes
- ResourceHOInstances5
- implicit def catsEffectMonoidForResource[F[_], A](implicit A0: Monoid[A]): Monoid[Resource[F, A]]
- Definition Classes
- ResourceFOInstances0
- implicit def catsEffectSemigroupForResource[F[_], A](implicit A0: Semigroup[A]): ResourceSemigroup[F, A]
- Definition Classes
- ResourceFOInstances1
- implicit def catsEffectSemigroupKForResource[F[_], A](implicit F0: MonadCancel[F, Throwable], K0: SemigroupK[F], G0: Make[F]): ResourceSemigroupK[F]
- Definition Classes
- ResourceHOInstances0
- implicit def catsEffectSyncForResource[F[_]](implicit F0: Sync[F]): Sync[[β$27$]Resource[F, β$27$]]
- Definition Classes
- ResourceHOInstances1
- implicit def catsEffectTemporalForResource[F[_]](implicit F0: Temporal[F]): Temporal[[β$26$]Resource[F, β$26$]]
- Definition Classes
- ResourceHOInstances1
- def cede[F[_]](implicit F: GenSpawn[F, _]): Resource[F, Unit]
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- implicit def commutativeApplicativeForResource[F[_]](implicit arg0: Concurrent[F]): CommutativeApplicative[[β$23$]T[[β$19$]Resource[F, β$19$], β$23$]]
- def cont[F[_], K, R](body: Cont[[β$15$]Resource[F, β$15$], K, R])(implicit F: Async[F]): Resource[F, R]
- def deferred[F[_], A](implicit F: GenConcurrent[F, _]): Resource[F, Deferred[[β$13$]Resource[F, β$13$], A]]
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def eval[F[_], A](fa: F[A]): Resource[F, A]
Lifts an applicative into a resource.
Lifts an applicative into a resource. The resource has a no-op release. Preserves interruptibility of
fa
.- fa
the value to lift into a resource
- def executionContext[F[_]](implicit F: Async[F]): Resource[F, ExecutionContext]
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- def fromAutoCloseable[F[_], A <: AutoCloseable](acquire: F[A])(implicit F: Sync[F]): Resource[F, A]
Creates a Resource by wrapping a Java AutoCloseable.
Creates a Resource by wrapping a Java AutoCloseable.
In most real world cases, implementors of AutoCloseable are blocking as well, so the close action runs in the blocking context.
- F
the type of the effect
- A
the type of the autocloseable resource
- acquire
The effect with the resource to acquire.
- F
the effect type in which the resource was acquired and will be released
- returns
a Resource that will automatically close after use
import cats.effect._ import scala.io.Source def reader(data: String): Resource[IO, Source] = Resource.fromAutoCloseable(IO.blocking { Source.fromString(data) })
, 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) })
Examples: - def fromDestroyable[F[_], A <: Destroyable](acquire: F[A])(implicit F: Sync[F]): Resource[F, A]
Creates a Resource by wrapping a Java Destroyable.
Creates a Resource by wrapping a Java Destroyable.
- F
the type of the effect
- A
the type of the destroyable resource
- acquire
The effect with the resource to acquire.
- F
the effect type in which the resource was acquired and will be released
- returns
a Resource that will automatically destroy after use
- Definition Classes
- ResourcePlatform
import java.security.KeyStore.PasswordProtection import cats.effect.{IO, Resource} def passwordProtection(getPassword: IO[Array[Char]]): Resource[IO, PasswordProtection] = Resource.fromDestroyable( getPassword.map(new PasswordProtection(_)) )
, import java.security.KeyStore.PasswordProtection import cats.effect.{Resource, Sync} import cats.syntax.all._ def passwordProtection[F[_]](getPassword: F[Array[Char]])(implicit F: Sync[F]): Resource[F, PasswordProtection] = Resource.fromDestroyable( getPassword.map(new PasswordProtection(_)) )
Examples: - final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def liftK[F[_]]: ~>[F, [β$9$]Resource[F, β$9$]]
Lifts an applicative into a resource as a
FunctionK
.Lifts an applicative into a resource as a
FunctionK
. The resource has a no-op release. - def make[F[_], A](acquire: F[A])(release: (A) => F[Unit])(implicit F: Functor[F]): Resource[F, A]
Creates a resource from an acquiring effect and a release function.
Creates a resource from an acquiring effect and a release function.
- F
the effect type in which the resource is acquired and released
- A
the type of the resource
- acquire
an effect to acquire a resource
- release
a function to effectfully release the resource returned by
acquire
- def makeCase[F[_], A](acquire: F[A])(release: (A, ExitCase) => F[Unit])(implicit F: Functor[F]): Resource[F, A]
Creates a resource from an acquiring effect and a release function that can discriminate between different exit cases.
Creates a resource from an acquiring effect and a release function that can discriminate between different exit cases.
- F
the effect type in which the resource is acquired and released
- A
the type of the resource
- acquire
a function to effectfully acquire a resource
- release
a function to effectfully release the resource returned by
acquire
- def makeCaseFull[F[_], A](acquire: (Poll[F]) => F[A])(release: (A, ExitCase) => F[Unit])(implicit F: Functor[F]): Resource[F, A]
Creates a resource from a possibly cancelable acquiring effect and a release function that can discriminate between different exit cases.
Creates a resource from a possibly cancelable acquiring effect and a release function that can discriminate between different exit cases.
The acquiring effect takes a
Poll[F]
to allow for cancelable 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.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 when the actions in
use
orflatMap
fail, succeed, or get canceled)- F
the effect type in which the resource is acquired and released
- A
the type of the resource
- acquire
an effect to acquire a resource, possibly interruptibly
- release
a function to effectfully release the resource returned by
acquire
- def makeFull[F[_], A](acquire: (Poll[F]) => F[A])(release: (A) => F[Unit])(implicit F: Functor[F]): Resource[F, A]
Creates a resource from a possibly cancelable acquiring effect and a release function.
Creates a resource from a possibly cancelable acquiring effect and a release function.
The acquiring effect takes a
Poll[F]
to allow for cancelable 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.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 when the actions in
use
orflatMap
fail, succeed, or get canceled)- F
the effect type in which the resource is acquired and released
- A
the type of the resource
- acquire
an effect to acquire a resource, possibly interruptibly
- release
a function to effectfully release the resource returned by
acquire
- def monotonic[F[_]](implicit F: Clock[F]): Resource[F, FiniteDuration]
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def never[F[_], A](implicit F: GenSpawn[F, _]): Resource[F, A]
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- def onFinalize[F[_]](release: F[Unit])(implicit arg0: Applicative[F]): Resource[F, Unit]
Lifts a finalizer into a resource.
Lifts a finalizer into a resource. The resource has a no-op allocation.
- def onFinalizeCase[F[_]](release: (ExitCase) => F[Unit])(implicit arg0: Applicative[F]): Resource[F, Unit]
Creates a resource that allocates immediately without any effects, but calls
release
when closing, providing the the usage completed with. - implicit def parallelForResource[F[_]](implicit arg0: Concurrent[F]): Aux[[β$20$]Resource[F, β$20$], [β$21$]T[[β$19$]Resource[F, β$19$], β$21$]]
- def pure[F[_], A](a: A): Resource[F, A]
Lifts a pure value into a resource.
Lifts a pure value into a resource. The resource has a no-op release.
- a
the value to lift into a resource
- def race[F[_], A, B](rfa: Resource[F, A], rfb: Resource[F, B])(implicit arg0: Concurrent[F]): Resource[F, Either[A, B]]
Races the evaluation of two resource allocations and returns the result of the winner, except in the case of cancelation.
- def raiseError[F[_], A, E](e: E)(implicit F: ApplicativeError[F, E]): Resource[F, A]
- def realTime[F[_]](implicit F: Clock[F]): Resource[F, FiniteDuration]
- def ref[F[_], A](a: A)(implicit F: GenConcurrent[F, _]): Resource[F, Ref[[β$14$]Resource[F, β$14$], A]]
- def sleep[F[_]](time: Duration)(implicit F: GenTemporal[F, _]): Resource[F, Unit]
- def suspend[F[_], A](hint: Type)(thunk: => A)(implicit F: Sync[F]): Resource[F, A]
- def suspend[F[_], A](fr: F[Resource[F, A]]): Resource[F, A]
Given a
Resource
suspended inF[_]
, lifts it in theResource
context. - final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- def uncancelable[F[_], A](body: (Poll[[β$11$]Resource[F, β$11$]]) => Resource[F, A])(implicit F: MonadCancel[F, Throwable]): Resource[F, A]
- def unique[F[_]](implicit F: Unique[F]): Resource[F, Token]
- def unit[F[_]]: Resource[F, Unit]
A resource with a no-op allocation and a no-op release.
- 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()
- object ExitCase extends Serializable
Deprecated Value Members
- def catsEffectMonadForResource[F[_]](F: Monad[F]): Monad[[β$35$]Resource[F, β$35$]]
- Definition Classes
- ResourceHOInstances5
- Annotations
- @deprecated
- Deprecated
(Since version 3.4.0) Use overload without constraint
- def catsEffectMonoidForResource[F[_], A](F0: Monad[F], A0: Monoid[A]): Monoid[Resource[F, A]]
- Definition Classes
- ResourceFOInstances0
- Annotations
- @deprecated
- Deprecated
(Since version 3.4.0) Use overload without monad constraint
- def catsEffectSemigroupForResource[F[_], A](F0: Monad[F], A0: Semigroup[A]): ResourceSemigroup[F, A]
- Definition Classes
- ResourceFOInstances1
- Annotations
- @deprecated
- Deprecated
(Since version 3.4.0) Use overload without monad constraint
- def sleep[F[_]](time: FiniteDuration, F: GenTemporal[F, _]): Resource[F, Unit]
- Annotations
- @deprecated
- Deprecated
(Since version 3.4.0) Use overload with Duration