Resource

object Resource
Companion:
class
trait Sum
trait Mirror
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]
object ExitCase
Companion:
class
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
final implicit class NestedSyntax[F[_], A](val self: Resource[[_] =>> Resource[F, _$98], A]) extends AnyVal
final case class Pure[F[_], +A](a: A) extends Resource[F, A]

Types

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

Inherited types

type MirroredElemLabels <: Tuple

The names of the product elements

The names of the product elements

Inherited from:
Mirror

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 parameters:
A

the type of the resource

F

the effect type in which the resource is acquired and released

Value parameters:
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 parameters:
A

the type of the resource

F

the effect type in which the resource is acquired and released

Value parameters:
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 parameters:
A

the type of the resource

F

the effect type in which the resource is acquired and released

Value parameters:
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[_] : Concurrent, A, B](rfa: Resource[F, A], rfb: Resource[F, B]): 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, _$81], K, R])(implicit F: Async[F]): Resource[F, R]
def deferred[F[_], A](implicit F: GenConcurrent[F, _]): Resource[F, Deferred[[_] =>> Resource[F, _$71], 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 parameters:
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 parameters:
A

the type of the autocloseable resource

F

the type of the effect

Value parameters:
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, _$58]]

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 parameters:
A

the type of the resource

F

the effect type in which the resource is acquired and released

Value parameters:
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 parameters:
A

the type of the resource

F

the effect type in which the resource is acquired and released

Value parameters:
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 parameters:
A

the type of the resource

F

the effect type in which the resource is acquired and released

Value parameters:
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 parameters:
A

the type of the resource

F

the effect type in which the resource is acquired and released

Value parameters:
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[_] : Applicative](release: F[Unit]): 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[_] : Applicative](release: ExitCase => F[Unit]): 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 parameters:
a

the value to lift into a resource

def race[F[_] : Concurrent, A, B](rfa: Resource[F, A], rfb: Resource[F, B]): 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, _$74], 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, _$65]] => 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.

Implicits

Implicits

final implicit def NestedSyntax[F[_], A](self: Resource[[_] =>> Resource[F, _$98], A]): NestedSyntax[F, A]
implicit def parallelForResource[F[_] : Concurrent]: Aux[[_] =>> Resource[F, _$103], [_] =>> Par[F, _$104]]

Inherited implicits

implicit def catsEffectAsyncForResource[F[_]](implicit F0: Async[F]): Async[[_] =>> Resource[F, _$107]]
Inherited from:
ResourceHOInstances0
implicit def catsEffectClockForResource[F[_]](implicit F0: Clock[F], FA: Applicative[[_] =>> Resource[F, _$116]]): Clock[[_] =>> Resource[F, _$117]]
Inherited from:
ResourceHOInstances2
implicit def catsEffectConcurrentForResource[F[_]](implicit F0: Concurrent[F]): Concurrent[[_] =>> Resource[F, _$114]]
Inherited from:
ResourceHOInstances2
implicit def catsEffectMonadCancelForResource[F[_]](implicit F0: MonadCancel[F, Throwable]): MonadCancel[[_] =>> Resource[F, _$119], Throwable]
Inherited from:
ResourceHOInstances3
implicit def catsEffectMonadErrorForResource[F[_], E](implicit F0: MonadError[F, E]): MonadError[[_] =>> Resource[F, _$121], E]
Inherited from:
ResourceHOInstances4
implicit def catsEffectMonadForResource[F[_]](implicit F0: Monad[F]): Monad[[_] =>> Resource[F, _$123]]
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, _$112]]
Inherited from:
ResourceHOInstances1
implicit def catsEffectTemporalForResource[F[_]](implicit F0: Temporal[F]): Temporal[[_] =>> Resource[F, _$110]]
Inherited from:
ResourceHOInstances1