Skip to main content Link Search Menu Expand Document (external link)

Resource overview

Added in v1.0.0


Table of contents


constructors

auto

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

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

Added in v1.0.0

manual

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

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

Added in v1.0.0

getters

get

Retrieves the current value stored in the cache.

Signature

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

Added in v1.0.0

models

Resource (interface)

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

Signature

export interface Resource<E, A> extends Resource.Variance<E, A> {
  /** @internal */
  readonly scopedRef: ScopedRef.ScopedRef<Exit.Exit<E, A>>
  /** @internal */
  acquire(): Effect.Effect<Scope.Scope, E, A>
}

Added in v1.0.0

symbols

ResourceTypeId

Signature

export declare const ResourceTypeId: typeof ResourceTypeId

Added in v1.0.0

ResourceTypeId (type alias)

Signature

export type ResourceTypeId = typeof ResourceTypeId

Added in v1.0.0

utils

Resource (namespace)

Added in v1.0.0

Variance (interface)

Signature

export interface Variance<E, A> {
  readonly [ResourceTypeId]: {
    _E: (_: never) => E
    _A: (_: never) => A
  }
}

Added in v1.0.0

refresh

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

Signature

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

Added in v1.0.0