<A, E>(u: unknown): u is Deferred<A, E>Checks whether a value is a Deferred.
When to use
Use to validate unknown values at runtime boundaries before treating them as
Deferred values.
export const const isDeferred: <A, E>(
u: unknown
) => u is Deferred<A, E>
Checks whether a value is a Deferred.
When to use
Use to validate unknown values at runtime boundaries before treating them as
Deferred values.
isDeferred = <function (type parameter) A in <A, E>(u: unknown): u is Deferred<A, E>A, function (type parameter) E in <A, E>(u: unknown): u is Deferred<A, E>E>(u: unknownu: unknown): u: unknownu is 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 <A, E>(u: unknown): u is Deferred<A, E>A, function (type parameter) E in <A, E>(u: unknown): u is Deferred<A, E>E> => hasProperty<"~effect/Deferred">(self: unknown, property: "~effect/Deferred"): self is { [K in "~effect/Deferred"]: unknown; } (+1 overload)Checks whether a value has a given property key.
When to use
Use when you need a Predicate guard for property access on unknown
values with a simple structural object check.
Details
Uses the in operator and isObjectKeyword. This does not check property
value types.
Example (Guarding object properties)
import { Predicate } from "effect"
const hasName = Predicate.hasProperty("name")
const data: unknown = { name: "Ada" }
if (hasName(data)) {
console.log(data.name)
}
hasProperty(u: unknownu, const TypeId: "~effect/Deferred"TypeId)