Context.Reference<Metadata<unknown, unknown>>Context reference containing metadata for the currently running schedule step.
Details
Repeat, retry, stream, and channel scheduling operations provide this service to effects run between schedule steps. The default value contains undefined input and output values, zero duration, and zeroed timing fields before any schedule step has produced metadata.
export const const CurrentMetadata: Context.Reference<
Metadata<unknown, unknown>
>
const CurrentMetadata: {
key: string;
Service: {
output: Output;
duration: Duration.Duration;
input: Input;
attempt: number;
start: number;
now: number;
elapsed: number;
elapsedSincePrevious: number;
};
defaultValue: () => Shape;
of: (this: void, self: Metadata<unknown, unknown>) => Metadata<unknown, unknown>;
context: (self: Metadata<unknown, unknown>) => Context.Context<never>;
use: (f: (service: Metadata<unknown, unknown>) => Effect<A, E, R>) => Effect<A, E, R>;
useSync: (f: (service: Metadata<unknown, unknown>) => A) => Effect<A, never, never>;
Identifier: Identifier;
stack: string | 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; <…;
toString: () => string;
toJSON: () => unknown;
}
Context reference containing metadata for the currently running schedule step.
Details
Repeat, retry, stream, and channel scheduling operations provide this service
to effects run between schedule steps. The default value contains undefined
input and output values, zero duration, and zeroed timing fields before any
schedule step has produced metadata.
CurrentMetadata = import ContextContext.const Reference: <Service>(
key: string,
options: {
readonly defaultValue: () => Service
}
) => Reference<Service>
Creates a context key with a default value.
When to use
Use when you need to define a context key with a lazily computed default
value.
Details
Context.Reference allows you to create a key that can hold a value. You
can provide a default value for the service, which will automatically be used
when the context is accessed, or override it with a custom implementation
when needed. The default value is computed lazily and cached on the
reference.
Example (Creating references with default values)
import { Context } from "effect"
// Create a reference with a default value
const LoggerRef = Context.Reference("Logger", {
defaultValue: () => ({ log: (msg: string) => console.log(msg) })
})
// The reference provides the default value when accessed from an empty context
const context = Context.empty()
const logger = Context.get(context, LoggerRef)
// You can also override the default value
const customContext = Context.make(LoggerRef, {
log: (msg: string) => `Custom: ${msg}`
})
const customLogger = Context.get(customContext, LoggerRef)
Reference<interface Metadata<Output = unknown, Input = unknown>Extended metadata that includes both input metadata and the output value from the schedule.
Metadata>("effect/Schedule/CurrentMetadata", {
defaultValue: LazyArg<{
input: undefined
output: undefined
duration: Duration.Duration
attempt: number
start: number
now: number
elapsed: number
elapsedSincePrevious: number
}>
defaultValue: constant<A>(value: A): LazyArg<A>Creates a zero-argument function that always returns the provided value.
When to use
Use when you need a thunk or callback that returns the same value on every
invocation.
Example (Creating a constant thunk)
import { Function } from "effect"
import * as assert from "node:assert"
const constNull = Function.constant(null)
assert.deepStrictEqual(constNull(), null)
assert.deepStrictEqual(constNull(), null)
constant({
input: undefinedinput: var undefinedundefined,
output: undefinedoutput: var undefinedundefined,
duration: Duration.Duration(property) duration: {
value: DurationValue;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
duration: import DurationDuration.const zero: Durationconst zero: {
value: DurationValue;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
A Duration representing zero time.
Example (Referencing the zero duration)
import { Duration } from "effect"
console.log(Duration.toMillis(Duration.zero)) // 0
zero,
attempt: numberattempt: 0,
start: numberstart: 0,
now: numbernow: 0,
elapsed: numberelapsed: 0,
elapsedSincePrevious: numberelapsedSincePrevious: 0
})
})