Resource

object Resource extends ResourceFOInstances0 with ResourceHOInstances0 with ResourcePlatform
Companion
class
trait Sum
trait Mirror
trait ResourcePlatform
trait ResourceHOInstances0
trait ResourceHOInstances1
trait ResourceHOInstances2
trait ResourceHOInstances3
trait ResourceHOInstances4
trait ResourceHOInstances5
class ResourceFOInstances0
class ResourceFOInstances1
class Object
trait Matchable
class Any

Type members

Classlikes

final case class Allocate[F[_], 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.

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]

Resource data constructor that encodes the flatMap operation.

Resource data constructor that encodes the flatMap operation.

final case class Eval[F[_], A](fa: F[A]) extends Resource[F, A]
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.

Type for signaling the exit condition of an effectful computation, that may either succeed, fail with an error or get canceled.

The types of exit signals are:

Companion
object
object ExitCase
Companion
class
final class NestedSyntax[F[_], A](val self: Resource[[_] =>> Resource[F, _$110], A]) extends AnyVal
final case class Pure[F[_], +A](a: A) extends Resource[F, A]

Types

type Par[F[_], A] = T[[_] =>> Resource[F, _$114], A]

Inherited types

type MirroredElemLabels <: Tuple

The names of the product elements

The names of the product elements

Inherited from
Mirror
type MirroredLabel <: String

The name of the type

The name of the type

Inherited from
Mirror

Value members

Concrete methods

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.

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

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.

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[_], 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 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

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 both[F[_], A, B](rfa: Resource[F, A], rfb: Resource[F, B])(implicit evidence$3: Concurrent[F]): Resource[F, (A, B)]

Allocates two resources concurrently, and combines their results in a tuple.

Allocates two resources concurrently, and combines their results in a tuple.

def canceled[F[_]](implicit F: MonadCancel[F, _]): Resource[F, Unit]
def cede[F[_]](implicit F: GenSpawn[F, _]): Resource[F, Unit]
def cont[F[_], K, R](body: Cont[[_] =>> Resource[F, _$91], K, R])(implicit F: Async[F]): Resource[F, R]
def deferred[F[_], A](implicit F: GenConcurrent[F, _]): Resource[F, Deferred[[_] =>> Resource[F, _$81], A]]
def eval[F[_], A](fa: F[A]): Resource[F, A]

Lifts an applicative into a resource. The resource has a no-op release. Preserves interruptibility of fa.

Lifts an applicative into a resource. The resource has a no-op release. Preserves interruptibility of fa.

Value Params
fa

the value to lift into a resource

def executionContext[F[_]](implicit F: Async[F]): Resource[F, ExecutionContext]
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.

Example:

 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)
   })
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

def liftK[F[_]]: FunctionK[F, [_] =>> Resource[F, _$64]]

Lifts an applicative into a resource as a FunctionK. The resource has a no-op release.

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.

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[_], 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.

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 makeCaseFull[F[_], A](acquire: Poll[F] => 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.

The acquiring effect takes a Poll[F] to allow for interruptible 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 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 makeFull[F[_], A](acquire: Poll[F] => F[A])(release: A => 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.

The acquiring effect takes a Poll[F] to allow for interruptible 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 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 monotonic[F[_]](implicit F: Clock[F]): Resource[F, FiniteDuration]
def never[F[_], A](implicit F: GenSpawn[F, _]): Resource[F, A]
def onFinalize[F[_]](release: F[Unit])(implicit evidence$1: Applicative[F]): Resource[F, Unit]

Lifts a finalizer into a resource. The resource has a no-op allocation.

Lifts a finalizer into a resource. The resource has a no-op allocation.

def onFinalizeCase[F[_]](release: ExitCase => F[Unit])(implicit evidence$2: 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.

Creates a resource that allocates immediately without any effects, but calls release when closing, providing the the usage completed with.

def pure[F[_], A](a: A): Resource[F, A]

Lifts a pure value into a resource. The resource has a no-op release.

Lifts a pure value into a resource. The resource has a no-op release.

Value Params
a

the value to lift into a resource

def race[F[_], A, B](rfa: Resource[F, A], rfb: Resource[F, B])(implicit evidence$4: 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.

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[[_] =>> Resource[F, _$84], A]]
def sleep[F[_]](time: FiniteDuration)(implicit F: GenTemporal[F, _]): Resource[F, Unit]
def suspend[F[_], A](fr: F[Resource[F, A]]): Resource[F, A]

Given a Resource suspended in F[_], lifts it in the Resource context.

Given a Resource suspended in F[_], lifts it in the Resource context.

def suspend[F[_], A](hint: Type)(thunk: => A)(implicit F: Sync[F]): Resource[F, A]
def uncancelable[F[_], A](body: Poll[[_] =>> Resource[F, _$71]] => 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.

A resource with a no-op allocation and a no-op release.

Inherited methods

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.

Example:

 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(_))
   )
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

Inherited from
ResourcePlatform

Implicits

Implicits

implicit def parallelForResource[F[_]](implicit evidence$5: Concurrent[F]): Aux[[_] =>> Resource[F, _$116], [_] =>> Par[F, _$117]]

Inherited implicits

implicit def catsEffectAsyncForResource[F[_]](implicit F0: Async[F]): Async[[_] =>> Resource[F, _$120]]
Inherited from
ResourceHOInstances0
implicit def catsEffectClockForResource[F[_]](implicit F0: Clock[F], FA: Applicative[[_] =>> Resource[F, _$129]]): Clock[[_] =>> Resource[F, _$130]]
Inherited from
ResourceHOInstances2
implicit def catsEffectConcurrentForResource[F[_]](implicit F0: Concurrent[F]): Concurrent[[_] =>> Resource[F, _$127]]
Inherited from
ResourceHOInstances2
implicit def catsEffectMonadCancelForResource[F[_]](implicit F0: MonadCancel[F, Throwable]): MonadCancel[[_] =>> Resource[F, _$132], Throwable]
Inherited from
ResourceHOInstances3
implicit def catsEffectMonadErrorForResource[F[_], E](implicit F0: MonadError[F, E]): MonadError[[_] =>> Resource[F, _$134], E]
Inherited from
ResourceHOInstances4
implicit def catsEffectMonadForResource[F[_]](implicit F0: Monad[F]): Monad[[_] =>> Resource[F, _$136]]
Inherited from
ResourceHOInstances5
implicit def catsEffectMonoidForResource[F[_], A](implicit F0: Monad[F], A0: Monoid[A]): Monoid[Resource[F, A]]
Inherited from
ResourceFOInstances0
implicit def catsEffectSemigroupForResource[F[_], A](implicit F0: Monad[F], A0: Semigroup[A]): ResourceSemigroup[F, A]
Inherited from
ResourceFOInstances1
implicit def catsEffectSemigroupKForResource[F[_], A](implicit F0: MonadCancel[F, Throwable], K0: SemigroupK[F], G0: Make[F]): ResourceSemigroupK[F]
Inherited from
ResourceHOInstances0
implicit def catsEffectSyncForResource[F[_]](implicit F0: Sync[F]): Sync[[_] =>> Resource[F, _$125]]
Inherited from
ResourceHOInstances1
implicit def catsEffectTemporalForResource[F[_]](implicit F0: Temporal[F]): Temporal[[_] =>> Resource[F, _$123]]
Inherited from
ResourceHOInstances1