Resource

cats.effect.kernel.Resource
See theResource companion class
object Resource

Attributes

Companion
class
Source
Resource.scala
Graph
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
Resource.type

Members list

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.

Attributes

Source
Resource.scala
Supertypes
trait Product
trait Equals
class Resource[F, A]
trait Serializable
class Object
trait Matchable
class Any
Show all
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.

Attributes

Source
Resource.scala
Supertypes
trait Product
trait Equals
class Resource[F, A]
trait Serializable
class Object
trait Matchable
class Any
Show all
final case class Eval[F[_], A](fa: F[A]) extends Resource[F, A]

Attributes

Source
Resource.scala
Supertypes
trait Product
trait Equals
class Resource[F, A]
trait Serializable
class Object
trait Matchable
class Any
Show all
object ExitCase

Attributes

Companion
trait
Source
Resource.scala
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
ExitCase.type
sealed trait ExitCase extends Product, 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:

Attributes

Companion
object
Source
Resource.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
Known subtypes
object Canceled.type
class Errored
object Succeeded.type
final implicit class NestedSyntax[F[_], A](val self: Resource[[_] =>> Resource[F, _$108], A]) extends AnyVal

Attributes

Source
Resource.scala
Supertypes
class AnyVal
trait Matchable
class Any
final case class Pure[F[_], +A](a: A) extends Resource[F, A]

Attributes

Source
Resource.scala
Supertypes
trait Product
trait Equals
class Resource[F, A]
trait Serializable
class Object
trait Matchable
class Any
Show all

Types

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

Attributes

Source
Resource.scala

Inherited types

type MirroredElemLabels <: Tuple

The names of the product elements

The names of the product elements

Attributes

Inherited from:
Mirror
Source
Mirror.scala
type MirroredLabel <: String

The name of the type

The name of the type

Attributes

Inherited from:
Mirror
Source
Mirror.scala

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

Attributes

See also

make for a version that separates the needed resource with its finalizer tuple in two parameters

Source
Resource.scala
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

Attributes

See also

makeCase for a version that separates the needed resource with its finalizer tuple in two parameters

Source
Resource.scala
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 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

Attributes

See also

makeFull for a version that separates the needed resource with its finalizer tuple in two parameters

Source
Resource.scala
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.

Attributes

Source
Resource.scala
def canceled[F[_]](implicit F: MonadCancel[F, _]): Resource[F, Unit]

Attributes

Source
Resource.scala
def cede[F[_]](implicit F: GenSpawn[F, _]): Resource[F, Unit]

Attributes

Source
Resource.scala
def cont[F[_], K, R](body: Cont[[_] =>> Resource[F, _$91], K, R])(implicit F: Async[F]): Resource[F, R]

Attributes

Source
Resource.scala
def deferred[F[_], A](implicit F: GenConcurrent[F, _]): Resource[F, Deferred[[_] =>> Resource[F, _$80], A]]

Attributes

Source
Resource.scala
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.

Value parameters

fa

the value to lift into a resource

Attributes

Source
Resource.scala
def executionContext[F[_]](implicit F: Async[F]): Resource[F, ExecutionContext]

Attributes

Source
Resource.scala
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.

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.

Attributes

Returns

a Resource that will automatically close after use

Example

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)
  })
Source
Resource.scala
def liftK[F[_]]: FunctionK[F, [_] =>> Resource[F, _$67]]

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.

Attributes

Source
Resource.scala
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

Attributes

Source
Resource.scala
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

Attributes

Source
Resource.scala
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 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

Attributes

Source
Resource.scala
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 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

Attributes

Source
Resource.scala
def monotonic[F[_]](implicit F: Clock[F]): Resource[F, FiniteDuration]

Attributes

Source
Resource.scala
def never[F[_], A](implicit F: GenSpawn[F, _]): Resource[F, A]

Attributes

Source
Resource.scala
def onFinalize[F[_] : Applicative](release: F[Unit]): Resource[F, Unit]

Lifts a finalizer into a resource.

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

Attributes

Source
Resource.scala
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.

Attributes

Source
Resource.scala
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.

Value parameters

a

the value to lift into a resource

Attributes

Source
Resource.scala
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.

Attributes

Source
Resource.scala
def raiseError[F[_], A, E](e: E)(implicit F: ApplicativeError[F, E]): Resource[F, A]

Attributes

Source
Resource.scala
def realTime[F[_]](implicit F: Clock[F]): Resource[F, FiniteDuration]

Attributes

Source
Resource.scala
def ref[F[_], A](a: A)(implicit F: GenConcurrent[F, _]): Resource[F, Ref[[_] =>> Resource[F, _$83], A]]

Attributes

Source
Resource.scala
def sleep[F[_]](time: Duration)(implicit F: GenTemporal[F, _]): Resource[F, Unit]

Attributes

Source
Resource.scala
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.

Attributes

Source
Resource.scala
def suspend[F[_], A](hint: Type)(thunk: => A)(implicit F: Sync[F]): Resource[F, A]

Attributes

Source
Resource.scala
def uncancelable[F[_], A](body: Poll[[_] =>> Resource[F, _$74]] => Resource[F, A])(implicit F: MonadCancel[F, Throwable]): Resource[F, A]

Attributes

Source
Resource.scala
def unique[F[_]](implicit F: Unique[F]): Resource[F, Token]

Attributes

Source
Resource.scala
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.

Attributes

Source
Resource.scala

Deprecated methods

def sleep[F[_]](time: FiniteDuration, F: GenTemporal[F, _]): Resource[F, Unit]

Attributes

Deprecated
true
Source
Resource.scala

Deprecated and Inherited methods

def catsEffectMonadForResource[F[_]](F: Monad[F]): Monad[[_] =>> Resource[F, _$140]]

Attributes

Deprecated
true
Inherited from:
ResourceHOInstances5 (hidden)
Source
Resource.scala
def catsEffectMonoidForResource[F[_], A](F0: Monad[F], A0: Monoid[A]): Monoid[Resource[F, A]]

Attributes

Deprecated
true
Inherited from:
ResourceFOInstances0 (hidden)
Source
Resource.scala
def catsEffectSemigroupForResource[F[_], A](F0: Monad[F], A0: Semigroup[A]): ResourceSemigroup[F, A]

Attributes

Deprecated
true
Inherited from:
ResourceFOInstances1 (hidden)
Source
Resource.scala

Implicits

Implicits

final implicit def NestedSyntax[F[_], A](self: Resource[[_] =>> Resource[F, _$108], A]): NestedSyntax[F, A]

Attributes

Source
Resource.scala
implicit def commutativeApplicativeForResource[F[_] : Concurrent]: CommutativeApplicative[[_] =>> Par[F, _$117]]

Attributes

Source
Resource.scala
implicit def parallelForResource[F[_] : Concurrent]: Aux[[_] =>> Resource[F, _$113], [_] =>> Par[F, _$114]]

Attributes

Source
Resource.scala

Inherited implicits

implicit def catsEffectAsyncForResource[F[_]](implicit F0: Async[F]): Async[[_] =>> Resource[F, _$120]]

Attributes

Inherited from:
ResourceHOInstances0 (hidden)
Source
Resource.scala
implicit def catsEffectClockForResource[F[_]](implicit F0: Clock[F], FA: Applicative[[_] =>> Resource[F, _$129]]): Clock[[_] =>> Resource[F, _$130]]

Attributes

Inherited from:
ResourceHOInstances2 (hidden)
Source
Resource.scala
implicit def catsEffectConcurrentForResource[F[_]](implicit F0: Concurrent[F]): Concurrent[[_] =>> Resource[F, _$127]]

Attributes

Inherited from:
ResourceHOInstances2 (hidden)
Source
Resource.scala
final implicit def catsEffectDeferForResource[F[_]]: Defer[[_] =>> Resource[F, _$132]]

Attributes

Inherited from:
ResourceHOInstances2 (hidden)
Source
Resource.scala
implicit def catsEffectMonadCancelForResource[F[_]](implicit F0: MonadCancel[F, Throwable]): MonadCancel[[_] =>> Resource[F, _$134], Throwable]

Attributes

Inherited from:
ResourceHOInstances3 (hidden)
Source
Resource.scala
implicit def catsEffectMonadErrorForResource[F[_], E](implicit F0: MonadError[F, E]): MonadError[[_] =>> Resource[F, _$136], E]

Attributes

Inherited from:
ResourceHOInstances4 (hidden)
Source
Resource.scala
implicit def catsEffectMonadForResource[F[_]]: Monad[[_] =>> Resource[F, _$138]]

Attributes

Inherited from:
ResourceHOInstances5 (hidden)
Source
Resource.scala
implicit def catsEffectMonoidForResource[F[_], A](implicit A0: Monoid[A]): Monoid[Resource[F, A]]

Attributes

Inherited from:
ResourceFOInstances0 (hidden)
Source
Resource.scala
implicit def catsEffectSemigroupForResource[F[_], A](implicit A0: Semigroup[A]): ResourceSemigroup[F, A]

Attributes

Inherited from:
ResourceFOInstances1 (hidden)
Source
Resource.scala
implicit def catsEffectSemigroupKForResource[F[_], A](implicit F0: MonadCancel[F, Throwable], K0: SemigroupK[F], G0: Make[F]): ResourceSemigroupK[F]

Attributes

Inherited from:
ResourceHOInstances0 (hidden)
Source
Resource.scala
implicit def catsEffectSyncForResource[F[_]](implicit F0: Sync[F]): Sync[[_] =>> Resource[F, _$125]]

Attributes

Inherited from:
ResourceHOInstances1 (hidden)
Source
Resource.scala
implicit def catsEffectTemporalForResource[F[_]](implicit F0: Temporal[F]): Temporal[[_] =>> Resource[F, _$123]]

Attributes

Inherited from:
ResourceHOInstances1 (hidden)
Source
Resource.scala