Resource
Resource:
object
Defined in: Core/Resource.ts:31
Type Declaration
Section titled “Type Declaration”combine
Section titled “combine”combine: <
E,A,B>(resourceA,resourceB) =>Resource<E, readonly [A,B]>
Acquires two resources in sequence and presents them as a tuple. Resources are released in reverse order: the second is released before the first.
If the second resource fails to acquire, the first is released immediately before returning the error.
Type Parameters
Section titled “Type Parameters”E
A
B
Parameters
Section titled “Parameters”resourceA
Section titled “resourceA”Resource<E, A>
resourceB
Section titled “resourceB”Resource<E, B>
Returns
Section titled “Returns”Resource<E, readonly [A, B]>
Example
Section titled “Example”from:
object
from.handlers
Section titled “from.handlers”handlers: <
E,A>(acquire,release) =>Resource<E,A> =makeHandlers
Creates a Resource from an acquire operation that may fail and a release function.
Type Parameters
Section titled “Type Parameters”E
A
Parameters
Section titled “Parameters”acquire
Section titled “acquire”Result<E, A>
release
Section titled “release”(a) => Task<void>
Returns
Section titled “Returns”Resource<E, A>
Example
Section titled “Example”from.Task
Section titled “from.Task”Task: <
E,A>(acquire,release) =>Resource<E,A> =makeTask
Creates a Resource from an acquire operation that cannot fail. Use this when opening the resource is guaranteed to succeed, such as in-memory locks, counters, or timers.
Type Parameters
Section titled “Type Parameters”E
A
Parameters
Section titled “Parameters”acquire
Section titled “acquire”Task<A>
release
Section titled “release”(a) => Task<void>
Returns
Section titled “Returns”Resource<E, A>
Example
Section titled “Example”use: <
E,A,B>(f) => (resource) =>Result<E,B>
Acquires the resource, runs f with it, then releases it.
Release always runs, even when f returns an error.
If acquire fails, f and release are both skipped and the error is returned.
Type Parameters
Section titled “Type Parameters”E
A
B
Parameters
Section titled “Parameters”(a) => Result<E, B>
Returns
Section titled “Returns”(resource) => Result<E, B>