Entry<A, E>Represents a low-level cache entry containing a deferred lookup result and an optional expiration timestamp.
When to use
Use when inspecting a Cache's low-level map and you need the stored
deferred lookup result or expiration timestamp for a key.
Details
An expiresAt value of undefined means the entry does not expire.
export interface interface Entry<A, E>Represents a low-level cache entry containing a deferred lookup result and
an optional expiration timestamp.
When to use
Use when inspecting a Cache's low-level map and you need the stored
deferred lookup result or expiration timestamp for a key.
Details
An expiresAt value of undefined means the entry does not expire.
Entry<function (type parameter) A in Entry<A, E>A, function (type parameter) E in Entry<A, E>E> {
Entry<A, E>.expiresAt: number | undefinedexpiresAt: number | undefined
readonly Entry<A, E>.deferred: Deferred.Deferred<A, E>(property) Entry<A, E>.deferred: {
effect: Effect<A, E>;
resumes: Array<(effect: Effect<A, E>) => void> | undefined;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
deferred: import DeferredDeferred.interface Deferred<in out A, in out E = never>A Deferred represents an asynchronous variable that can be set exactly
once, with the ability for an arbitrary number of fibers to suspend (by
calling Deferred.await) and automatically resume when the variable is set.
When to use
Use to coordinate multiple fibers around a value or failure that will be
supplied exactly once.
Example (Creating a Deferred for inter-fiber communication)
import { Deferred, Effect, Fiber } from "effect"
// Create and use a Deferred for inter-fiber communication
const program = Effect.gen(function*() {
// Create a Deferred that will hold a string value
const deferred: Deferred.Deferred<string> = yield* Deferred.make<string>()
// Fork a fiber that will set the deferred value
const producer = yield* Effect.forkChild(
Effect.gen(function*() {
yield* Effect.sleep("100 millis")
yield* Deferred.succeed(deferred, "Hello, World!")
})
)
// Fork a fiber that will await the deferred value
const consumer = yield* Effect.forkChild(
Effect.gen(function*() {
const value = yield* Deferred.await(deferred)
console.log("Received:", value)
return value
})
)
// Wait for both fibers to complete
yield* Fiber.join(producer)
const result = yield* Fiber.join(consumer)
return result
})
Companion namespace containing type-level metadata for Deferred.
When to use
Use to reference type-level metadata associated with Deferred.
Deferred<function (type parameter) A in Entry<A, E>A, function (type parameter) E in Entry<A, E>E>
}