final case class Suspend[F[_], A](resource: F[Resource[F, A]]) extends Resource[F, A] with InvariantResource[F, A] with Product with Serializable
Resource data constructor that suspends the evaluation of another
resource value.
- Source
- Resource.scala
- Alphabetic
- By Inheritance
- Suspend
- Serializable
- Product
- Equals
- InvariantResource
- Resource
- ResourceLike
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
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 allocated[G[x] >: F[x], B >: A](implicit F: BracketThrow[G]): G[(B, G[Unit])]
Given a
Resource, possibly built by composing multipleResources monadically, returns the acquired resource, as well as an action that runs all the finalizers for releasing it.Given a
Resource, possibly built by composing multipleResources monadically, returns the acquired resource, as well as an action that runs all the finalizers for releasing it.If the outer
Ffails or is interrupted,allocatedguarantees that the finalizers will be called. However, if the outerFsucceeds, it's up to the user to ensure the returnedF[Unit]is called onceAneeds to be released. If the returnedF[Unit]is not called, the finalizers will not be run.For this reason, this is an advanced and potentially unsafe api which can cause a resource leak if not used correctly, please prefer use as the standard way of running a
Resourceprogram.Use cases include interacting with side-effectful apis that expect separate acquire and release actions (like the
beforeandaftermethods of many test frameworks), or complex library code that needs to modify or move the finalizer for an existing resource.- Definition Classes
- ResourceLike
- def allocated_[G[x] >: F[x], B >: A](implicit F: BracketThrow[G]): G[(B, G[Unit])]
Implementation of
allocated, which is declared inResourceLikeImplementation of
allocated, which is declared inResourceLike- Attributes
- protected
- Definition Classes
- Resource
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native() @IntrinsicCandidate()
- def combineK[G[x] >: F[x], B >: A](that: Resource[G, B])(implicit F: Sync[G], K: SemigroupK[G]): Resource[G, B]
Combines two
Resourceinstances by lifting the behaviour of aSemigroupKinstance into the resource contextCombines two
Resourceinstances by lifting the behaviour of aSemigroupKinstance into the resource context- Definition Classes
- Resource
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def evalMap[G[x] >: F[x], B](f: (A) => G[B])(implicit F: Applicative[G]): Resource[G, B]
Applies an effectful transformation to the allocated resource.
Applies an effectful transformation to the allocated resource. Like a
flatMaponF[A]while maintaining the resource context- Definition Classes
- ResourceLike
- def evalMap_[G[x] >: F[x], B](f: (A) => G[B])(implicit F: Applicative[G]): Resource[G, B]
Implementation of
evalMap, which is declared inResourceLikeImplementation of
evalMap, which is declared inResourceLike- Attributes
- protected
- Definition Classes
- Resource
- def evalTap[G[x] >: F[x], B](f: (A) => G[B])(implicit F: Applicative[G]): Resource[G, A]
Applies an effectful transformation to the allocated resource.
Applies an effectful transformation to the allocated resource. Like a
flatTaponF[A]while maintaining the resource context- Definition Classes
- ResourceLike
- def evalTap_[G[x] >: F[x], B](f: (A) => G[B])(implicit F: Applicative[G]): Resource[G, A]
Implementation of
evalTap, which is declared inResourceLikeImplementation of
evalTap, which is declared inResourceLike- Attributes
- protected
- Definition Classes
- Resource
- def flatMap[G[x] >: F[x], B](f: (A) => Resource[G, B]): Resource[G, B]
Implementation for the
flatMapoperation, as described via thecats.Monadtype class.Implementation for the
flatMapoperation, as described via thecats.Monadtype class.- Definition Classes
- ResourceLike
- def flatMap_[G[x] >: F[x], B](f: (A) => Resource[G, B]): Resource[G, B]
Implementation of
flatMap, which is declared inResourceLikeImplementation of
flatMap, which is declared inResourceLike- Attributes
- protected
- Definition Classes
- Resource
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @IntrinsicCandidate()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def map[G[x] >: F[x], B](f: (A) => B)(implicit F: Applicative[G]): Resource[G, B]
Given a mapping function, transforms the resource provided by this Resource.
Given a mapping function, transforms the resource provided by this Resource.
This is the standard
Functor.map.- Definition Classes
- ResourceLike
- def mapK[G[x] >: F[x], H[_]](f: ~>[G, H])(implicit D: Defer[H], G: Applicative[H]): Resource[H, A]
Given a natural transformation from
FtoG, transforms this Resource from effectFto effectG.Given a natural transformation from
FtoG, transforms this Resource from effectFto effectG.- Definition Classes
- Resource
- def map_[G[x] >: F[x], B](f: (A) => B)(implicit F: Applicative[G]): Resource[G, B]
Implementation of
map, which is declared inResourceLikeImplementation of
map, which is declared inResourceLike- Attributes
- protected
- Definition Classes
- Resource
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @IntrinsicCandidate()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @IntrinsicCandidate()
- def onFinalize[G[x] >: F[x]](finalizer: G[Unit])(implicit F: Applicative[G]): Resource[G, A]
Runs
finalizerwhen this resource is closed.Runs
finalizerwhen this resource is closed. Unlike the release action passed toResource.make, this will run even if resource acquisition fails or is canceled.- Definition Classes
- Resource
- def onFinalizeCase[G[x] >: F[x]](f: (ExitCase[Throwable]) => G[Unit])(implicit F: Applicative[G]): Resource[G, A]
Like
onFinalize, but the action performed depends on the exit case.Like
onFinalize, but the action performed depends on the exit case.- Definition Classes
- Resource
- def parZip[G[x] >: F[x], B](that: Resource[G, B])(implicit arg0: Sync[G], arg1: Parallel[G]): Resource[G, (A, B)]
Allocates two resources concurrently, and combines their results in a tuple.
Allocates two resources concurrently, and combines their results in a tuple.
The finalizers for the two resources are also run concurrently with each other, but within _each_ of the two resources, nested finalizers are run in the usual reverse order of acquisition.
Note that
Resourcealso comes with acats.Parallelinstance that offers more convenient access to the same functionality asparZip, for example viaparMapN:def mkResource(name: String) = { val acquire = IO(scala.util.Random.nextInt(1000).millis).flatMap(IO.sleep) *> IO(println(s"Acquiring $$name")).as(name) val release = IO(println(s"Releasing $$name")) Resource.make(acquire)(release) } val r = (mkResource("one"), mkResource("two")) .parMapN((s1, s2) => s"I have $s1 and $s2") .use(msg => IO(println(msg)))
- Definition Classes
- ResourceLike
- def parZip_[G[x] >: F[x], B](that: Resource[G, B])(implicit arg0: Sync[G], arg1: Parallel[G]): Resource[G, (A, B)]
Implementation of
parZip, which is declared inResourceLikeImplementation of
parZip, which is declared inResourceLike- Attributes
- protected
- Definition Classes
- Resource
- def productElementNames: Iterator[String]
- Definition Classes
- Product
- val resource: F[Resource[F, A]]
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def use[G[x] >: F[x], B](f: (A) => G[B])(implicit F: BracketThrow[G]): G[B]
Allocates a resource and supplies it to the given function.
Allocates a resource and supplies it to the given function. The resource is released as soon as the resulting
F[B]is completed, whether normally or as a raised error.- f
the function to apply to the allocated resource
- returns
the result of applying [F] to
- Definition Classes
- ResourceLike
- def use_[G[x] >: F[x], B](f: (A) => G[B])(implicit F: BracketThrow[G]): G[B]
Implementation of
use, which is declared inResourceLikeImplementation of
use, which is declared inResourceLike- Attributes
- protected
- Definition Classes
- Resource
- 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()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
Deprecated Value Members
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable]) @Deprecated
- Deprecated

This is the API documentation for the cats-effect library.
See the cats.effect package for a quick overview.
Links
Canonical documentation links:
Related Cats links (the core):