- Companion
- class
Type members
Classlikes
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.
Resource
data constructor that encodes the flatMap
operation.
Resource
data constructor that encodes the flatMap
operation.
Value members
Concrete methods
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
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
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
Allocates two resources concurrently, and combines their results in a tuple.
Allocates two resources concurrently, and combines their results in a tuple.
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
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
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.
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
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
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
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
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.
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.
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
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.
Inherited methods
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
Inherited implicits
- Inherited from
- ResourceHOInstances2
- Inherited from
- ResourceHOInstances2
- Inherited from
- ResourceHOInstances3
- Inherited from
- ResourceHOInstances4
- Inherited from
- ResourceFOInstances0
- Inherited from
- ResourceFOInstances1
- Inherited from
- ResourceHOInstances0
- Inherited from
- ResourceHOInstances1