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

Resource overview

Added in v2.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: <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>

Added in v2.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: <A, E, R>(
  acquire: Effect.Effect<A, E, R>
) => Effect.Effect<Resource<A, E>, never, Scope.Scope | R>

Added in v2.0.0

getters

get

Retrieves the current value stored in the cache.

Signature

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

Added in v2.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<in out A, in out E = never> extends Effect.Effect<A, E>, Resource.Variance<A, E> {
  /** @internal */
  readonly scopedRef: ScopedRef.ScopedRef<Exit.Exit<A, E>>
  /** @internal */
  readonly acquire: Effect.Effect<A, E, Scope.Scope>

  readonly [Unify.typeSymbol]?: unknown
  readonly [Unify.unifySymbol]?: ResourceUnify<this>
  readonly [Unify.ignoreSymbol]?: ResourceUnifyIgnore
}

Added in v2.0.0

ResourceUnify (interface)

Signature

export interface ResourceUnify<A extends { [Unify.typeSymbol]?: any }> extends Effect.EffectUnify<A> {
  Resource?: () => Extract<A[Unify.typeSymbol], Resource<any, any>>
}

Added in v3.9.0

ResourceUnifyIgnore (interface)

Signature

export interface ResourceUnifyIgnore extends Effect.EffectUnifyIgnore {
  Effect?: true
}

Added in v3.9.0

symbols

ResourceTypeId

Signature

export declare const ResourceTypeId: typeof ResourceTypeId

Added in v2.0.0

ResourceTypeId (type alias)

Signature

export type ResourceTypeId = typeof ResourceTypeId

Added in v2.0.0

utils

Resource (namespace)

Added in v2.0.0

Variance (interface)

Signature

export interface Variance<in out A, in out E> {
  readonly [ResourceTypeId]: {
    _A: Types.Invariant<A>
    _E: Types.Invariant<E>
  }
}

Added in v2.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: <A, E>(self: Resource<A, E>) => Effect.Effect<void, E>

Added in v2.0.0