Skip to content

Resource

10 exports Added in v2.0.0 Source

Constructors

auto

Added in v2.0.0 Source

Creates a new Resource value that is automatically refreshed according to the specified policy. Note that error retrying is not performed automatically, so if you want to retry on errors, you should first apply retry policies to the acquisition effect before passing it to this constructor.

Signature

declare const auto: <A, E, R, Out, R2>(
  acquire: Effect.Effect<A, E, R>,
  policy: Schedule.Schedule<Out, unknown, R2>,
) => Effect.Effect<Resource<A, E>, never, R | R2 | Scope.Scope>;

manual

Added in v2.0.0 Source

Creates a new Resource value that must be manually refreshed by calling the refresh method. Note that error retrying is not performed automatically, so if you want to retry on errors, you should first apply retry policies to the acquisition effect before passing it to this constructor.

Signature

declare const manual: <A, E, R>(
  acquire: Effect.Effect<A, E, R>,
) => Effect.Effect<Resource<A, E>, never, Scope.Scope | R>;

Getters

get

Added in v2.0.0 Source

Retrieves the current value stored in the cache.

Signature

declare const get: <A, E>(self: Resource<A, E>) => Effect.Effect<A, E>;

Models

Resource interface

Added in v2.0.0 Source

A Resource is a possibly resourceful value that is loaded into memory, and which can be refreshed either manually or automatically.

Signature

interface Resource<in out A, in out E = never> extends Effect<A, E>, Variance<A, E> {
  readonly [ignoreSymbol]?: ResourceUnifyIgnore;
  readonly [typeSymbol]?: unknown;
  readonly [unifySymbol]?: ResourceUnify<Resource<A, E>>;
}

ResourceUnify interface

Added in v3.9.0 Source

Signature

interface ResourceUnify<
  A extends {
    [typeSymbol]?: any;
  },
> extends EffectUnify<A> {
  Resource?: () => Extract<A[typeof typeSymbol], Resource<any, any>>;
}

ResourceUnifyIgnore interface

Added in v3.9.0 Source

Signature

interface ResourceUnifyIgnore extends EffectUnifyIgnore {
  Effect?: true;
}

Other

Resource

Added in v2.0.0 Source

Symbols

Signature

declare const ResourceTypeId: unique symbol;

ResourceTypeId type

Added in v2.0.0 Source

Signature

type ResourceTypeId = typeof ResourceTypeId;

Utils

refresh

Added in v2.0.0 Source

Refreshes the cache. This method will not return until either the refresh is successful, or the refresh operation fails.

Signature

declare const refresh: <A, E>(self: Resource<A, E>) => Effect.Effect<void, E>;