WorkPool — Priority Lanes
Draft — paired with a runnable example; tip-check before treating as SSOT.
Source: examples/forms/queue/workpool-priority-lanes.ts Run: pnpm run example:workpool-priority Hub: Examples → Queue
WorkPool — N named lanes, add(item, lane?), and sizes: Record<string, number>.
// KNOWN QUIRK: this block typechecks clean under dev, tsx, and scripts/check-twoslash.ts, but
// errors (2488/2345/7006) ONLY inside the bundled waku-build prerender — with typescript/twoslash
// externalized, so it is not the dual-instance problem. Sole holdout of the 2026-07 sweep;
// diagnose separately, then remove this directive.
import { import EffectEffect, import SchemaSchema } from "effect"
import { import WorkPoolWorkPool } from "hyperlink-ts"
const const JobSchema: Schema.Struct<{
readonly id: Schema.String
readonly kind: Schema.String
}>
const JobSchema: {
Type: Struct.Type<Fields>;
Encoded: Struct.Encoded<Fields>;
DecodingServices: Struct.DecodingServices<Fields>;
EncodingServices: Struct.EncodingServices<Fields>;
Iso: Struct.Iso<Fields>;
fields: Fields;
mapFields: (f: (fields: { readonly id: Schema.String; readonly kind: Schema.String }) => To, options?: { readonly unsafePreserveChecks?: boolean | undefined } | undefined) => Schema.Struct<{ [K in keyof Readonly<To>]: Readonly<To>[K]; }>;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Schema.Annotations.Bottom<Schema.Struct.ReadonlySide<{ readonly id: Schema.String; readonly kind: Schema.String; }, 'Type'>, readonly []>) => Schema.Struct<{ readonly id: Schema.String; readonly kind: Schema.String; }>;
annotateKey: (annotations: Schema.Annotations.Key<Schema.Struct.ReadonlySide<{ readonly id: Schema.String; readonly kind: Schema.String }, 'Type'>>) => Schema.Struct<{ readonly id: Schema.String; readonly kind: Schema.String }>;
check: (checks_0: Check<Schema.Struct.ReadonlySide<{ readonly id: Schema.String; readonly kind: Schema.String }, 'Type'>>, ...checks: Array<Check<Schema.Struct.ReadonlySide<{ readonly id: Schema.String; readonly kind: Schema.String }, 'Type'>>>) …;
rebuild: (ast: Objects) => Schema.Struct<{ readonly id: Schema.String; readonly kind: Schema.String }>;
make: (input: Struct.ReadonlyMakeIn<{ readonly id: String; readonly kind: String }>, options?: MakeOptions) => Struct.ReadonlySide<{ readonly id: String; readonly kind: String }, 'Type'>;
makeOption: (input: Struct.ReadonlyMakeIn<{ readonly id: String; readonly kind: String }>, options?: MakeOptions) => Option_.Option<Struct.ReadonlySide<{ readonly id: String; readonly kind: String }, 'Type'>>;
makeEffect: (input: Struct.ReadonlyMakeIn<{ readonly id: String; readonly kind: String }>, options?: MakeOptions) => Effect.Effect<Struct.ReadonlySide<{ readonly id: String; readonly kind: String }, 'Type'>, SchemaError, never>;
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; <…;
}
JobSchema = import SchemaSchema.function Struct<
Fields extends Struct.Fields
>(fields: Fields): Struct<Fields>
Defines a struct schema from a map of field schemas.
Details
Each field value is a schema. Use
optionalKey
or
optional
to
mark fields as optional, and
mutableKey
to mark them as mutable.
The resulting schema's Type is a readonly object type with the fields'
decoded types. The Encoded form mirrors the field schemas' encoded types.
Example (Defining a basic struct)
import { Schema } from "effect"
const Person = Schema.Struct({
name: Schema.String,
age: Schema.Number,
email: Schema.optionalKey(Schema.String)
})
// { readonly name: string; readonly age: number; readonly email?: string }
type Person = typeof Person.Type
const alice = Schema.decodeUnknownSync(Person)({ name: "Alice", age: 30 })
console.log(alice)
// { name: 'Alice', age: 30 }
Struct({ id: Schema.String(property) id: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<string, readonly []>) => Schema.String;
annotateKey: (annotations: Schema.Annotations.Key<string>) => Schema.String;
check: (checks_0: Check<string>, ...checks: Array<Check<string>>) => Schema.String;
rebuild: (ast: String) => Schema.String;
make: (input: string, options?: MakeOptions) => string;
makeOption: (input: string, options?: MakeOptions) => Option_.Option<string>;
makeEffect: (input: string, options?: MakeOptions) => Effect.Effect<string, SchemaError, never>;
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; <…;
}
id: import SchemaSchema.const String: Stringconst String: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<string, readonly []>) => Schema.String;
annotateKey: (annotations: Schema.Annotations.Key<string>) => Schema.String;
check: (checks_0: Check<string>, ...checks: Array<Check<string>>) => Schema.String;
rebuild: (ast: String) => Schema.String;
make: (input: string, options?: MakeOptions) => string;
makeOption: (input: string, options?: MakeOptions) => Option_.Option<string>;
makeEffect: (input: string, options?: MakeOptions) => Effect.Effect<string, SchemaError, never>;
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; <…;
}
Type-level representation of
String
.
Schema for string values. Validates that the input is typeof "string".
String, kind: Schema.String(property) kind: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<string, readonly []>) => Schema.String;
annotateKey: (annotations: Schema.Annotations.Key<string>) => Schema.String;
check: (checks_0: Check<string>, ...checks: Array<Check<string>>) => Schema.String;
rebuild: (ast: String) => Schema.String;
make: (input: string, options?: MakeOptions) => string;
makeOption: (input: string, options?: MakeOptions) => Option_.Option<string>;
makeEffect: (input: string, options?: MakeOptions) => Effect.Effect<string, SchemaError, never>;
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; <…;
}
kind: import SchemaSchema.const String: Stringconst String: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<string, readonly []>) => Schema.String;
annotateKey: (annotations: Schema.Annotations.Key<string>) => Schema.String;
check: (checks_0: Check<string>, ...checks: Array<Check<string>>) => Schema.String;
rebuild: (ast: String) => Schema.String;
make: (input: string, options?: MakeOptions) => string;
makeOption: (input: string, options?: MakeOptions) => Option_.Option<string>;
makeEffect: (input: string, options?: MakeOptions) => Effect.Effect<string, SchemaError, never>;
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; <…;
}
Type-level representation of
String
.
Schema for string values. Validates that the input is typeof "string".
String })
/** Tag factory: config object — `{ payload, laneCount, namedLanes? }`. */
class class Jobsclass Jobs {
key: Identifier;
Service: {
enqueue: (payload: ReadonlyArray<{ item: Schema.Struct.ReadonlySide<{ readonly id: Schema.String; readonly kind: Schema.String }, 'Type'>; entryId: string; priority: 'high' | 'normal' | 'low'; attempts: number; timestamps: { readonly enqueuedAt: Ut…;
release: (payload: { options?: { readonly releaseId?: string | undefined; readonly attributes?: { readonly [x: string]: JsonValue } | undefined; readonly scope?: 'pendingOnly' | undefined } | undefined }) => Effect.Effect<ReadonlyArray<{ readonly i…;
releaseEncoded: (payload: { options?: { readonly releaseId?: string | undefined; readonly attributes?: { readonly [x: string]: JsonValue } | undefined; readonly scope?: 'pendingOnly' | undefined } | undefined }) => Effect.Effect<ReadonlyArray<{ readonly p…;
deadLetter: (payload: { selector: { readonly key?: string | undefined; readonly item?: Schema.Struct.ReadonlySide<{ readonly id: Schema.String; readonly kind: Schema.String }, 'Type'> | undefined; readonly entryId?: string | undefined }; options: { re…;
drop: (payload: { selector: { readonly key?: string | undefined; readonly item?: Schema.Struct.ReadonlySide<{ readonly id: Schema.String; readonly kind: Schema.String }, 'Type'> | undefined; readonly entryId?: string | undefined }; options: { re…;
events: Stream<Schema.Struct.ReadonlySide<{ readonly _tag: Schema.tag<'Start'>; readonly key: Schema.String }, 'Type'> | { readonly entries: ReadonlyArray<{ readonly item: Schema.Struct.ReadonlySide<{ readonly id: Schema.String; readonly kind: Sch…;
status: Subscribable<Schema.Struct.ReadonlySide<{ readonly sizes: Schema.$Record<Schema.String, Schema.Number>; readonly paused: Schema.Boolean; readonly inFlight: Schema.Number; readonly completed: Schema.Number; readonly phase: Schema.Literals<r…;
size: Subscribable<number>;
isEmpty: Subscribable<boolean>;
start: Effect.Effect<void, never, never>;
pause: Effect.Effect<void, never, never>;
resume: Effect.Effect<void, never, never>;
shutdown: Effect.Effect<void, never, never>;
clear: Effect.Effect<number, never, never>;
metrics: { readonly stream: Stream<{ readonly inFlight: number; readonly completed: number; readonly avgWaitMillis: { readonly high?: number | undefined; readonly normal?: number | undefined; readonly low?: number | undefined }; readonly windowStar…;
levelSizes: Effect.Effect<ReadonlyArray<number>, never, never>;
add: (arg0: unknown, arg1?: unknown) => Effect.Effect<void, never, never>;
};
}
Tag factory: config object — { payload, laneCount, namedLanes? }.
Jobs extends import WorkPoolWorkPool.const priority: <Self>() => {
<
F extends Schema.Struct.Fields,
Success extends Schema.Top,
HSelf
>(
key: string,
config: PriorityTagConfig<F, Success> & {
readonly node: NodeKey<HSelf>
}
): NodeBoundTag<
Self,
PriorityInstanceSpec<F>,
HSelf
>
<
F extends Schema.Struct.Fields,
Success extends Schema.Top = Schema.Void
>(
key: string,
config: PriorityTagConfig<F, Success>
): HyperlinkTag<Self, PriorityInstanceSpec<F>>
}
Define an N-level managed queue as a named service
Tag
(also exported as
priority
): class Jobs extends WorkPool.priority<Jobs>()("@app/Jobs", { … }) {}.
The priority (N-level lane) peer of
Tag
— same WorkPool, with laneCount /
namedLanes priority lanes and add(item, lane?). class Jobs extends
WorkPool.priority<Jobs>()("@app/Jobs", { payload, laneCount: 2 }) {}. The class is the Tag —
yield* Jobs resolves the handle,
layer
provides it and
serve
exposes it over RPC
(both dispatch to the leveled engine for a priority tag). payload is the item schema; optional
success / error add the worker wire schemas.
priority<class Jobsclass Jobs {
key: Identifier;
Service: {
enqueue: (payload: ReadonlyArray<{ item: Schema.Struct.ReadonlySide<{ readonly id: Schema.String; readonly kind: Schema.String }, 'Type'>; entryId: string; priority: 'high' | 'normal' | 'low'; attempts: number; timestamps: { readonly enqueuedAt: Ut…;
release: (payload: { options?: { readonly releaseId?: string | undefined; readonly attributes?: { readonly [x: string]: JsonValue } | undefined; readonly scope?: 'pendingOnly' | undefined } | undefined }) => Effect.Effect<ReadonlyArray<{ readonly i…;
releaseEncoded: (payload: { options?: { readonly releaseId?: string | undefined; readonly attributes?: { readonly [x: string]: JsonValue } | undefined; readonly scope?: 'pendingOnly' | undefined } | undefined }) => Effect.Effect<ReadonlyArray<{ readonly p…;
deadLetter: (payload: { selector: { readonly key?: string | undefined; readonly item?: Schema.Struct.ReadonlySide<{ readonly id: Schema.String; readonly kind: Schema.String }, 'Type'> | undefined; readonly entryId?: string | undefined }; options: { re…;
drop: (payload: { selector: { readonly key?: string | undefined; readonly item?: Schema.Struct.ReadonlySide<{ readonly id: Schema.String; readonly kind: Schema.String }, 'Type'> | undefined; readonly entryId?: string | undefined }; options: { re…;
events: Stream<Schema.Struct.ReadonlySide<{ readonly _tag: Schema.tag<'Start'>; readonly key: Schema.String }, 'Type'> | { readonly entries: ReadonlyArray<{ readonly item: Schema.Struct.ReadonlySide<{ readonly id: Schema.String; readonly kind: Sch…;
status: Subscribable<Schema.Struct.ReadonlySide<{ readonly sizes: Schema.$Record<Schema.String, Schema.Number>; readonly paused: Schema.Boolean; readonly inFlight: Schema.Number; readonly completed: Schema.Number; readonly phase: Schema.Literals<r…;
size: Subscribable<number>;
isEmpty: Subscribable<boolean>;
start: Effect.Effect<void, never, never>;
pause: Effect.Effect<void, never, never>;
resume: Effect.Effect<void, never, never>;
shutdown: Effect.Effect<void, never, never>;
clear: Effect.Effect<number, never, never>;
metrics: { readonly stream: Stream<{ readonly inFlight: number; readonly completed: number; readonly avgWaitMillis: { readonly high?: number | undefined; readonly normal?: number | undefined; readonly low?: number | undefined }; readonly windowStar…;
levelSizes: Effect.Effect<ReadonlyArray<number>, never, never>;
add: (arg0: unknown, arg1?: unknown) => Effect.Effect<void, never, never>;
};
}
Tag factory: config object — { payload, laneCount, namedLanes? }.
Jobs>()("examples/CustomJobs", {
PriorityTagConfig<{ readonly id: String; readonly kind: String; }, Void>.payload: Schema.Struct<{ readonly id: Schema.String; readonly kind: Schema.String }>(property) PriorityTagConfig<{ readonly id: String; readonly kind: String; }, Void>.payload: {
Type: Struct.Type<Fields>;
Encoded: Struct.Encoded<Fields>;
DecodingServices: Struct.DecodingServices<Fields>;
EncodingServices: Struct.EncodingServices<Fields>;
Iso: Struct.Iso<Fields>;
fields: Fields;
mapFields: (f: (fields: { readonly id: Schema.String; readonly kind: Schema.String }) => To, options?: { readonly unsafePreserveChecks?: boolean | undefined } | undefined) => Schema.Struct<{ [K in keyof Readonly<To>]: Readonly<To>[K]; }>;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Schema.Annotations.Bottom<Schema.Struct.ReadonlySide<{ readonly id: Schema.String; readonly kind: Schema.String; }, 'Type'>, readonly []>) => Schema.Struct<{ readonly id: Schema.String; readonly kind: Schema.String; }>;
annotateKey: (annotations: Schema.Annotations.Key<Schema.Struct.ReadonlySide<{ readonly id: Schema.String; readonly kind: Schema.String }, 'Type'>>) => Schema.Struct<{ readonly id: Schema.String; readonly kind: Schema.String }>;
check: (checks_0: Check<Schema.Struct.ReadonlySide<{ readonly id: Schema.String; readonly kind: Schema.String }, 'Type'>>, ...checks: Array<Check<Schema.Struct.ReadonlySide<{ readonly id: Schema.String; readonly kind: Schema.String }, 'Type'>>>) …;
rebuild: (ast: Objects) => Schema.Struct<{ readonly id: Schema.String; readonly kind: Schema.String }>;
make: (input: Struct.ReadonlyMakeIn<{ readonly id: String; readonly kind: String }>, options?: MakeOptions) => Struct.ReadonlySide<{ readonly id: String; readonly kind: String }, 'Type'>;
makeOption: (input: Struct.ReadonlyMakeIn<{ readonly id: String; readonly kind: String }>, options?: MakeOptions) => Option_.Option<Struct.ReadonlySide<{ readonly id: String; readonly kind: String }, 'Type'>>;
makeEffect: (input: Struct.ReadonlyMakeIn<{ readonly id: String; readonly kind: String }>, options?: MakeOptions) => Effect.Effect<Struct.ReadonlySide<{ readonly id: String; readonly kind: String }, 'Type'>, SchemaError, never>;
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; <…;
}
payload: const JobSchema: Schema.Struct<{
readonly id: Schema.String
readonly kind: Schema.String
}>
const JobSchema: {
Type: Struct.Type<Fields>;
Encoded: Struct.Encoded<Fields>;
DecodingServices: Struct.DecodingServices<Fields>;
EncodingServices: Struct.EncodingServices<Fields>;
Iso: Struct.Iso<Fields>;
fields: Fields;
mapFields: (f: (fields: { readonly id: Schema.String; readonly kind: Schema.String }) => To, options?: { readonly unsafePreserveChecks?: boolean | undefined } | undefined) => Schema.Struct<{ [K in keyof Readonly<To>]: Readonly<To>[K]; }>;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Schema.Annotations.Bottom<Schema.Struct.ReadonlySide<{ readonly id: Schema.String; readonly kind: Schema.String; }, 'Type'>, readonly []>) => Schema.Struct<{ readonly id: Schema.String; readonly kind: Schema.String; }>;
annotateKey: (annotations: Schema.Annotations.Key<Schema.Struct.ReadonlySide<{ readonly id: Schema.String; readonly kind: Schema.String }, 'Type'>>) => Schema.Struct<{ readonly id: Schema.String; readonly kind: Schema.String }>;
check: (checks_0: Check<Schema.Struct.ReadonlySide<{ readonly id: Schema.String; readonly kind: Schema.String }, 'Type'>>, ...checks: Array<Check<Schema.Struct.ReadonlySide<{ readonly id: Schema.String; readonly kind: Schema.String }, 'Type'>>>) …;
rebuild: (ast: Objects) => Schema.Struct<{ readonly id: Schema.String; readonly kind: Schema.String }>;
make: (input: Struct.ReadonlyMakeIn<{ readonly id: String; readonly kind: String }>, options?: MakeOptions) => Struct.ReadonlySide<{ readonly id: String; readonly kind: String }, 'Type'>;
makeOption: (input: Struct.ReadonlyMakeIn<{ readonly id: String; readonly kind: String }>, options?: MakeOptions) => Option_.Option<Struct.ReadonlySide<{ readonly id: String; readonly kind: String }, 'Type'>>;
makeEffect: (input: Struct.ReadonlyMakeIn<{ readonly id: String; readonly kind: String }>, options?: MakeOptions) => Effect.Effect<Struct.ReadonlySide<{ readonly id: String; readonly kind: String }, 'Type'>, SchemaError, never>;
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; <…;
}
JobSchema,
PriorityTagConfig<F extends Schema.Struct.Fields, Success extends Schema.Top = Void>.laneCount: numberlaneCount: 4,
PriorityTagConfig<F extends Schema.Struct.Fields, Success extends Schema.Top = Void>.namedLanes?: Readonly<Record<string, number>> | undefined(property) PriorityTagConfig<F extends Schema.Struct.Fields, Success extends Schema.Top = Void>.namedLanes?: {
interactive: number;
standard: number;
batch: number;
}
namedLanes: { interactive: numberinteractive: 0, standard: numberstandard: 2, batch: numberbatch: 3 },
}) {}
const const program: Effect.Effect<
void,
never,
Jobs
>
const program: {
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;
}
program = import EffectEffect.const gen: {
<Eff extends Effect<any, any, any>, AEff>(
f: () => Generator<Eff, AEff, never>
): Effect<
AEff,
[Eff] extends [never]
? never
: [Eff] extends [
Effect<infer _A, infer E, infer _R>
]
? E
: never,
[Eff] extends [never]
? never
: [Eff] extends [
Effect<infer _A, infer _E, infer R>
]
? R
: never
>
<Self, Eff extends Effect<any, any, any>, AEff>(
options: { readonly self: Self },
f: (this: Self) => Generator<Eff, AEff, never>
): Effect<
AEff,
[Eff] extends [never]
? never
: [Eff] extends [
Effect<infer _A, infer E, infer _R>
]
? E
: never,
[Eff] extends [never]
? never
: [Eff] extends [
Effect<infer _A, infer _E, infer R>
]
? R
: never
>
}
Provides a way to write effectful code using generator functions, simplifying
control flow and error handling.
When to use
Use when you want to write effectful code that looks and behaves like
synchronous code, while still handling asynchronous tasks, errors, and complex
control flow such as loops and conditions.
Generator functions work similarly to async/await but keep errors,
requirements, and interruption in the Effect type. You can yield* values
from effects and return the final result at the end.
Example (Sequencing effects with generators)
import { Data, Effect } from "effect"
class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
const addServiceCharge = (amount: number) => amount + 1
const applyDiscount = (
total: number,
discountRate: number
): Effect.Effect<number, DiscountRateError> =>
discountRate === 0
? Effect.fail(new DiscountRateError())
: Effect.succeed(total - (total * discountRate) / 100)
const fetchTransactionAmount = Effect.promise(() => Promise.resolve(100))
const fetchDiscountRate = Effect.promise(() => Promise.resolve(5))
export const program = Effect.gen(function*() {
const transactionAmount = yield* fetchTransactionAmount
const discountRate = yield* fetchDiscountRate
const discountedAmount = yield* applyDiscount(
transactionAmount,
discountRate
)
const finalAmount = addServiceCharge(discountedAmount)
return `Final amount to charge: ${finalAmount}`
})
gen(function* () {
const const queue: {
readonly enqueue: (payload: readonly {
item: Schema.Struct.ReadonlySide<{
readonly id: Schema.String;
readonly kind: Schema.String;
}, "Type">;
entryId: string;
priority: "high" | "normal" | "low";
attempts: number;
timestamps: {
readonly enqueuedAt: Utc;
readonly startedAt?: Utc | undefined;
readonly completedAt?: Utc | undefined;
readonly interruptedAt?: Utc | undefined;
};
key?: string | undefined;
lane?: number | undefined;
batchId?: string | undefined;
releaseId?: string | undefined;
sourceHyperlinkId?: string | undefined;
attributes?: {
...;
} | undefined;
}[]) => Effect.Effect<...>;
... 15 more ...;
readonly add: (arg0: unknown, arg1?: unknown) => Effect.Effect<...>;
}
queue = yield* class Jobsclass Jobs {
key: Identifier;
Service: {
enqueue: (payload: ReadonlyArray<{ item: Schema.Struct.ReadonlySide<{ readonly id: Schema.String; readonly kind: Schema.String }, 'Type'>; entryId: string; priority: 'high' | 'normal' | 'low'; attempts: number; timestamps: { readonly enqueuedAt: Ut…;
release: (payload: { options?: { readonly releaseId?: string | undefined; readonly attributes?: { readonly [x: string]: JsonValue } | undefined; readonly scope?: 'pendingOnly' | undefined } | undefined }) => Effect.Effect<ReadonlyArray<{ readonly i…;
releaseEncoded: (payload: { options?: { readonly releaseId?: string | undefined; readonly attributes?: { readonly [x: string]: JsonValue } | undefined; readonly scope?: 'pendingOnly' | undefined } | undefined }) => Effect.Effect<ReadonlyArray<{ readonly p…;
deadLetter: (payload: { selector: { readonly key?: string | undefined; readonly item?: Schema.Struct.ReadonlySide<{ readonly id: Schema.String; readonly kind: Schema.String }, 'Type'> | undefined; readonly entryId?: string | undefined }; options: { re…;
drop: (payload: { selector: { readonly key?: string | undefined; readonly item?: Schema.Struct.ReadonlySide<{ readonly id: Schema.String; readonly kind: Schema.String }, 'Type'> | undefined; readonly entryId?: string | undefined }; options: { re…;
events: Stream<Schema.Struct.ReadonlySide<{ readonly _tag: Schema.tag<'Start'>; readonly key: Schema.String }, 'Type'> | { readonly entries: ReadonlyArray<{ readonly item: Schema.Struct.ReadonlySide<{ readonly id: Schema.String; readonly kind: Sch…;
status: Subscribable<Schema.Struct.ReadonlySide<{ readonly sizes: Schema.$Record<Schema.String, Schema.Number>; readonly paused: Schema.Boolean; readonly inFlight: Schema.Number; readonly completed: Schema.Number; readonly phase: Schema.Literals<r…;
size: Subscribable<number>;
isEmpty: Subscribable<boolean>;
start: Effect.Effect<void, never, never>;
pause: Effect.Effect<void, never, never>;
resume: Effect.Effect<void, never, never>;
shutdown: Effect.Effect<void, never, never>;
clear: Effect.Effect<number, never, never>;
metrics: { readonly stream: Stream<{ readonly inFlight: number; readonly completed: number; readonly avgWaitMillis: { readonly high?: number | undefined; readonly normal?: number | undefined; readonly low?: number | undefined }; readonly windowStar…;
levelSizes: Effect.Effect<ReadonlyArray<number>, never, never>;
add: (arg0: unknown, arg1?: unknown) => Effect.Effect<void, never, never>;
};
description: string | undefined;
of: (this: void, self: { readonly enqueue: (payload: ReadonlyArray<{ item: Schema.Struct.ReadonlySide<{ readonly id: Schema.String; readonly kind: Schema.String }, 'Type'>; entryId: string; priority: 'high' | 'normal' | 'low'; attempts: number…;
context: (self: { readonly enqueue: (payload: ReadonlyArray<{ item: Schema.Struct.ReadonlySide<{ readonly id: Schema.String; readonly kind: Schema.String }, 'Type'>; entryId: string; priority: 'high' | 'normal' | 'low'; attempts: number; timestamps…;
use: (f: (service: { readonly enqueue: (payload: ReadonlyArray<{ item: Schema.Struct.ReadonlySide<{ readonly id: Schema.String; readonly kind: Schema.String }, 'Type'>; entryId: string; priority: 'high' | 'normal' | 'low'; attempts: number; tim…;
useSync: (f: (service: { readonly enqueue: (payload: ReadonlyArray<{ item: Schema.Struct.ReadonlySide<{ readonly id: Schema.String; readonly kind: Schema.String }, 'Type'>; entryId: string; priority: 'high' | 'normal' | 'low'; attempts: number; tim…;
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;
}
Tag factory: config object — { payload, laneCount, namedLanes? }.
Jobs
// Pair-style add — lane is a configured name or numeric index.
yield* const queue: {
readonly enqueue: (payload: readonly {
item: Schema.Struct.ReadonlySide<{
readonly id: Schema.String;
readonly kind: Schema.String;
}, "Type">;
entryId: string;
priority: "high" | "normal" | "low";
attempts: number;
timestamps: {
readonly enqueuedAt: Utc;
readonly startedAt?: Utc | undefined;
readonly completedAt?: Utc | undefined;
readonly interruptedAt?: Utc | undefined;
};
key?: string | undefined;
lane?: number | undefined;
batchId?: string | undefined;
releaseId?: string | undefined;
sourceHyperlinkId?: string | undefined;
attributes?: {
...;
} | undefined;
}[]) => Effect.Effect<...>;
... 15 more ...;
readonly add: (arg0: unknown, arg1?: unknown) => Effect.Effect<...>;
}
queue.add: (
arg0: unknown,
arg1?: unknown
) => Effect.Effect<void, never, never>
add({ id: stringid: "a", kind: stringkind: "email" }, "interactive")
yield* const queue: {
readonly enqueue: (payload: readonly {
item: Schema.Struct.ReadonlySide<{
readonly id: Schema.String;
readonly kind: Schema.String;
}, "Type">;
entryId: string;
priority: "high" | "normal" | "low";
attempts: number;
timestamps: {
readonly enqueuedAt: Utc;
readonly startedAt?: Utc | undefined;
readonly completedAt?: Utc | undefined;
readonly interruptedAt?: Utc | undefined;
};
key?: string | undefined;
lane?: number | undefined;
batchId?: string | undefined;
releaseId?: string | undefined;
sourceHyperlinkId?: string | undefined;
attributes?: {
...;
} | undefined;
}[]) => Effect.Effect<...>;
... 15 more ...;
readonly add: (arg0: unknown, arg1?: unknown) => Effect.Effect<...>;
}
queue.add: (
arg0: unknown,
arg1?: unknown
) => Effect.Effect<void, never, never>
add({ id: stringid: "b", kind: stringkind: "report" }, "batch")
yield* const queue: {
readonly enqueue: (payload: readonly {
item: Schema.Struct.ReadonlySide<{
readonly id: Schema.String;
readonly kind: Schema.String;
}, "Type">;
entryId: string;
priority: "high" | "normal" | "low";
attempts: number;
timestamps: {
readonly enqueuedAt: Utc;
readonly startedAt?: Utc | undefined;
readonly completedAt?: Utc | undefined;
readonly interruptedAt?: Utc | undefined;
};
key?: string | undefined;
lane?: number | undefined;
batchId?: string | undefined;
releaseId?: string | undefined;
sourceHyperlinkId?: string | undefined;
attributes?: {
...;
} | undefined;
}[]) => Effect.Effect<...>;
... 15 more ...;
readonly add: (arg0: unknown, arg1?: unknown) => Effect.Effect<...>;
}
queue.add: (
arg0: unknown,
arg1?: unknown
) => Effect.Effect<void, never, never>
add([{ id: stringid: "c", kind: stringkind: "email" }, { id: stringid: "d", kind: stringkind: "email" }], 2)
const const sizes: {
readonly [x: string]: number
}
sizes = (yield* const queue: {
readonly enqueue: (payload: readonly {
item: Schema.Struct.ReadonlySide<{
readonly id: Schema.String;
readonly kind: Schema.String;
}, "Type">;
entryId: string;
priority: "high" | "normal" | "low";
attempts: number;
timestamps: {
readonly enqueuedAt: Utc;
readonly startedAt?: Utc | undefined;
readonly completedAt?: Utc | undefined;
readonly interruptedAt?: Utc | undefined;
};
key?: string | undefined;
lane?: number | undefined;
batchId?: string | undefined;
releaseId?: string | undefined;
sourceHyperlinkId?: string | undefined;
attributes?: {
...;
} | undefined;
}[]) => Effect.Effect<...>;
... 15 more ...;
readonly add: (arg0: unknown, arg1?: unknown) => Effect.Effect<...>;
}
queue.status: Subscribable<
Schema.Struct.ReadonlySide<
{
readonly sizes: Schema.$Record<
Schema.String,
Schema.Number
>
readonly paused: Schema.Boolean
readonly inFlight: Schema.Number
readonly completed: Schema.Number
readonly phase: Schema.Literals<
readonly ["running", "draining", "off"]
>
},
"Type"
>
>
(property) status: {
get: Effect.Effect<A>;
changes: Stream.Stream<A>;
}
status.Subscribable<Struct<Fields extends Struct.Fields>.ReadonlySide<{ readonly sizes: $Record<String, Number>; readonly paused: Boolean; readonly inFlight: Number; readonly completed: Number; readonly phase: Literals<...>; }, "Type">>.get: Effect.Effect<A>(property) Subscribable<Struct<Fields extends Struct.Fields>.ReadonlySide<{ readonly sizes: $Record<String, Number>; readonly paused: Boolean; readonly inFlight: Number; readonly completed: Number; readonly phase: Literals<...>; }, "Type">>.get: {
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;
}
get).sizes: {
readonly [x: string]: number
}
sizes
yield* import EffectEffect.const log: (
...message: ReadonlyArray<any>
) => Effect<void>
Logs one or more messages using the default log level.
Example (Logging at the default level)
import { Effect } from "effect"
const program = Effect.gen(function*() {
yield* Effect.log("Starting computation")
const result = 2 + 2
yield* Effect.log("Result:", result)
yield* Effect.log("Multiple", "values", "can", "be", "logged")
return result
})
Effect.runPromise(program).then(console.log)
// Output:
// timestamp=2023-... level=INFO message="Starting computation"
// timestamp=2023-... level=INFO message="Result: 4"
// timestamp=2023-... level=INFO message="Multiple values can be logged"
// 4
log(
`sizes: ${var Object: ObjectConstructorProvides functionality common to all JavaScript objects.
Object.ObjectConstructor.entries<number>(o: {
[s: string]: number;
} | ArrayLike<number>): [string, number][] (+1 overload)
Returns an array of key/values of the enumerable own properties of an object
entries(const sizes: {
readonly [x: string]: number
}
sizes)
.Array<[string, number]>.map<string>(callbackfn: (value: [string, number], index: number, array: [string, number][]) => string, thisArg?: any): string[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map(([k: stringk, n: numbern]) => `${k: stringk}=${var String: StringConstructor
;(value?: any) => string
Allows manipulation and formatting of text strings and determination and location of substrings within strings.
String(n: numbern)}`)
.Array<string>.join(separator?: string): stringAdds all the elements of an array into a string, separated by the specified separator string.
join(", ")}`,
)
const const levelSizes: readonly number[]levelSizes = yield* const queue: {
readonly enqueue: (payload: readonly {
item: Schema.Struct.ReadonlySide<{
readonly id: Schema.String;
readonly kind: Schema.String;
}, "Type">;
entryId: string;
priority: "high" | "normal" | "low";
attempts: number;
timestamps: {
readonly enqueuedAt: Utc;
readonly startedAt?: Utc | undefined;
readonly completedAt?: Utc | undefined;
readonly interruptedAt?: Utc | undefined;
};
key?: string | undefined;
lane?: number | undefined;
batchId?: string | undefined;
releaseId?: string | undefined;
sourceHyperlinkId?: string | undefined;
attributes?: {
...;
} | undefined;
}[]) => Effect.Effect<...>;
... 15 more ...;
readonly add: (arg0: unknown, arg1?: unknown) => Effect.Effect<...>;
}
queue.levelSizes: Effect.Effect<
ReadonlyArray<number>,
never,
never
>
(property) levelSizes: {
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;
}
levelSizes
yield* import EffectEffect.const log: (
...message: ReadonlyArray<any>
) => Effect<void>
Logs one or more messages using the default log level.
Example (Logging at the default level)
import { Effect } from "effect"
const program = Effect.gen(function*() {
yield* Effect.log("Starting computation")
const result = 2 + 2
yield* Effect.log("Result:", result)
yield* Effect.log("Multiple", "values", "can", "be", "logged")
return result
})
Effect.runPromise(program).then(console.log)
// Output:
// timestamp=2023-... level=INFO message="Starting computation"
// timestamp=2023-... level=INFO message="Result: 4"
// timestamp=2023-... level=INFO message="Multiple values can be logged"
// 4
log(`levelSizes: ${const levelSizes: readonly number[]levelSizes.ReadonlyArray<number>.join(separator?: string): stringAdds all the elements of an array separated by the specified separator string.
join(", ")}`)
})
void import EffectEffect.const runPromise: <A, E>(
effect: Effect<A, E>,
options?: RunOptions | undefined
) => Promise<A>
Executes an effect and returns the result as a Promise.
When to use
Use when you need to execute an effect and work with the
result using Promise syntax, typically for compatibility with other
promise-based code.
If the effect succeeds, the promise will resolve with the result. If the
effect fails, the promise will reject with an error.
Example (Running a successful effect as a Promise)
import { Effect } from "effect"
Effect.runPromise(Effect.succeed(1)).then(console.log)
// Output: 1
Example (Running effects as promises)
//Example: Handling a Failing Effect as a Rejected Promise
import { Effect } from "effect"
Effect.runPromise(Effect.fail("my error")).catch(console.error)
// Output:
// (FiberFailure) Error: my error
runPromise(
const program: Effect.Effect<
void,
never,
Jobs
>
const program: {
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;
}
program.Pipeable.pipe<Effect.Effect<void, never, Jobs>, Effect.Effect<void, never, never>, Effect.Effect<void, never, never>>(this: Effect.Effect<void, never, Jobs>, ab: (_: Effect.Effect<void, never, Jobs>) => Effect.Effect<void, never, never>, bc: (_: Effect.Effect<void, never, never>) => Effect.Effect<void, never, never>): Effect.Effect<void, never, never> (+21 overloads)pipe(
import EffectEffect.const provide: {
<
Layers extends [
Layer.Any,
...Array<Layer.Any>
]
>(
layers: Layers,
options?:
| { readonly local?: boolean | undefined }
| undefined
): <A, E, R>(
self: Effect<A, E, R>
) => Effect<
A,
E | Layer.Error<Layers[number]>,
| Layer.Services<Layers[number]>
| Exclude<R, Layer.Success<Layers[number]>>
>
<ROut, E2, RIn>(
layer: Layer.Layer<ROut, E2, RIn>,
options?:
| { readonly local?: boolean | undefined }
| undefined
): <A, E, R>(
self: Effect<A, E, R>
) => Effect<A, E | E2, RIn | Exclude<R, ROut>>
<R2>(context: Context.Context<R2>): <A, E, R>(
self: Effect<A, E, R>
) => Effect<A, E, Exclude<R, R2>>
<
A,
E,
R,
Layers extends [
Layer.Any,
...Array<Layer.Any>
]
>(
self: Effect<A, E, R>,
layers: Layers,
options?:
| { readonly local?: boolean | undefined }
| undefined
): Effect<
A,
E | Layer.Error<Layers[number]>,
| Layer.Services<Layers[number]>
| Exclude<R, Layer.Success<Layers[number]>>
>
<A, E, R, ROut, E2, RIn>(
self: Effect<A, E, R>,
layer: Layer.Layer<ROut, E2, RIn>,
options?:
| { readonly local?: boolean | undefined }
| undefined
): Effect<A, E | E2, RIn | Exclude<R, ROut>>
<A, E, R, R2>(
self: Effect<A, E, R>,
context: Context.Context<R2>
): Effect<A, E, Exclude<R, R2>>
}
Provides dependencies to an effect using layers or a context. Use options.local
to build the layer every time; by default, layers are shared between provide
calls.
Example (Providing dependencies with a layer)
import { Context, Effect, Layer } from "effect"
interface Database {
readonly query: (sql: string) => Effect.Effect<string>
}
const Database = Context.Service<Database>("Database")
const DatabaseLive = Layer.succeed(Database)({
query: Effect.fn("Database.query")((sql: string) => Effect.succeed(`Result for: ${sql}`))
})
const program = Effect.gen(function*() {
const db = yield* Database
return yield* db.query("SELECT * FROM users")
})
const provided = Effect.provide(program, DatabaseLive)
Effect.runPromise(provided).then(console.log)
// Output: "Result for: SELECT * FROM users"
provide(
import WorkPoolWorkPool.const layerMemory: {
<
Self,
F extends QueueItemFields = QueueItemFields,
R = never,
RR = never,
Success extends Schema.Top = Schema.Void,
Error extends Schema.Top = Schema.Never
>(
tag: QueueTagFor<Self, F, Success, Error>,
config: QueueVerbConfig<
F,
QueueErrorValueOf<Error>,
R,
RR,
Success
>
): Layer.Layer<
Self | Local<Self> | Store.Storage,
never,
R | RR
>
<
Self,
F extends PriorityItemFields = PriorityItemFields,
E = never,
R = never,
RR = never
>(
tag: HyperlinkTag<
Self,
PriorityInstanceSpec<F>
>,
config: PriorityLayerConfig<
Schema.Struct<F>["Type"],
E,
R,
RR
>
): Layer.Layer<
Self | Local<Self> | Store.Storage,
never,
R | RR
>
}
Run this WorkPool locally — soft-defaults
Store.Storage
(R fulfilled; override by
providing an app store into this layer). Accepts a plain
Tag
or a
priority
tag and
dispatches to the matching engine.
layerMemory
is an alias for the same soft-default.
layerMemory(class Jobsclass Jobs {
key: Identifier;
Service: {
enqueue: (payload: ReadonlyArray<{ item: Schema.Struct.ReadonlySide<{ readonly id: Schema.String; readonly kind: Schema.String }, 'Type'>; entryId: string; priority: 'high' | 'normal' | 'low'; attempts: number; timestamps: { readonly enqueuedAt: Ut…;
release: (payload: { options?: { readonly releaseId?: string | undefined; readonly attributes?: { readonly [x: string]: JsonValue } | undefined; readonly scope?: 'pendingOnly' | undefined } | undefined }) => Effect.Effect<ReadonlyArray<{ readonly i…;
releaseEncoded: (payload: { options?: { readonly releaseId?: string | undefined; readonly attributes?: { readonly [x: string]: JsonValue } | undefined; readonly scope?: 'pendingOnly' | undefined } | undefined }) => Effect.Effect<ReadonlyArray<{ readonly p…;
deadLetter: (payload: { selector: { readonly key?: string | undefined; readonly item?: Schema.Struct.ReadonlySide<{ readonly id: Schema.String; readonly kind: Schema.String }, 'Type'> | undefined; readonly entryId?: string | undefined }; options: { re…;
drop: (payload: { selector: { readonly key?: string | undefined; readonly item?: Schema.Struct.ReadonlySide<{ readonly id: Schema.String; readonly kind: Schema.String }, 'Type'> | undefined; readonly entryId?: string | undefined }; options: { re…;
events: Stream<Schema.Struct.ReadonlySide<{ readonly _tag: Schema.tag<'Start'>; readonly key: Schema.String }, 'Type'> | { readonly entries: ReadonlyArray<{ readonly item: Schema.Struct.ReadonlySide<{ readonly id: Schema.String; readonly kind: Sch…;
status: Subscribable<Schema.Struct.ReadonlySide<{ readonly sizes: Schema.$Record<Schema.String, Schema.Number>; readonly paused: Schema.Boolean; readonly inFlight: Schema.Number; readonly completed: Schema.Number; readonly phase: Schema.Literals<r…;
size: Subscribable<number>;
isEmpty: Subscribable<boolean>;
start: Effect.Effect<void, never, never>;
pause: Effect.Effect<void, never, never>;
resume: Effect.Effect<void, never, never>;
shutdown: Effect.Effect<void, never, never>;
clear: Effect.Effect<number, never, never>;
metrics: { readonly stream: Stream<{ readonly inFlight: number; readonly completed: number; readonly avgWaitMillis: { readonly high?: number | undefined; readonly normal?: number | undefined; readonly low?: number | undefined }; readonly windowStar…;
levelSizes: Effect.Effect<ReadonlyArray<number>, never, never>;
add: (arg0: unknown, arg1?: unknown) => Effect.Effect<void, never, never>;
};
description: string | undefined;
of: (this: void, self: { readonly enqueue: (payload: ReadonlyArray<{ item: Schema.Struct.ReadonlySide<{ readonly id: Schema.String; readonly kind: Schema.String }, 'Type'>; entryId: string; priority: 'high' | 'normal' | 'low'; attempts: number…;
context: (self: { readonly enqueue: (payload: ReadonlyArray<{ item: Schema.Struct.ReadonlySide<{ readonly id: Schema.String; readonly kind: Schema.String }, 'Type'>; entryId: string; priority: 'high' | 'normal' | 'low'; attempts: number; timestamps…;
use: (f: (service: { readonly enqueue: (payload: ReadonlyArray<{ item: Schema.Struct.ReadonlySide<{ readonly id: Schema.String; readonly kind: Schema.String }, 'Type'>; entryId: string; priority: 'high' | 'normal' | 'low'; attempts: number; tim…;
useSync: (f: (service: { readonly enqueue: (payload: ReadonlyArray<{ item: Schema.Struct.ReadonlySide<{ readonly id: Schema.String; readonly kind: Schema.String }, 'Type'>; entryId: string; priority: 'high' | 'normal' | 'low'; attempts: number; tim…;
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;
}
Tag factory: config object — { payload, laneCount, namedLanes? }.
Jobs, {
laneCount: numberRequired lane count — one bounded queue per level index 0 … laneCount - 1.
laneCount: 4,
namedLanes?: Record<string, number> | undefined(property) namedLanes?: {
interactive: number;
standard: number;
batch: number;
}
Map configured names to lane indices (e.g. { interactive: 2, batch: 5 }).
namedLanes: { interactive: numberinteractive: 0, standard: numberstandard: 2, batch: numberbatch: 3 },
takeAlgorithm?: TakeAlgorithm | undefinedHow workers pick among non-empty lanes when taking the next item. "priority" is strict
lowest-index-first (the default 3-level behavior). "weighted" and "strict-descending"
apply to all configured levels; a
CustomTakeAlgorithm
function is also accepted.
takeAlgorithm: "weighted",
concurrency?: number | undefinedMax items processing concurrently (worker count).
concurrency: 2,
effect: (
item: Schema.Struct.ReadonlySide<
{
readonly id: Schema.String
readonly kind: Schema.String
},
"Type"
>,
ctx: WorkPool.EffectContext<
Schema.Struct.ReadonlySide<
{
readonly id: Schema.String
readonly kind: Schema.String
},
"Type"
>,
QueueEnqueueErrors,
never
>
) => Effect.Effect<void, never, never>
effect: (job: Schema.Struct.ReadonlySide<
{
readonly id: Schema.String
readonly kind: Schema.String
},
"Type"
>
(parameter) job: {
id: string;
kind: string;
}
job) => import EffectEffect.const logInfo: (
...message: ReadonlyArray<any>
) => Effect<void>
Logs one or more messages at the INFO level.
Example (Logging information)
import { Effect } from "effect"
const program = Effect.gen(function*() {
yield* Effect.logInfo("Application starting up")
yield* Effect.logInfo("Config loaded:", "production", "Port:", 3000)
// Useful for general information
const version = "1.2.3"
yield* Effect.logInfo("Application version:", version)
})
Effect.runPromise(program)
// Output:
// timestamp=2023-... level=INFO message="Application starting up"
// timestamp=2023-... level=INFO message="Config loaded: production Port: 3000"
// timestamp=2023-... level=INFO message="Application version: 1.2.3"
logInfo(`processed ${job: Schema.Struct.ReadonlySide<
{
readonly id: Schema.String
readonly kind: Schema.String
},
"Type"
>
(parameter) job: {
id: string;
kind: string;
}
job.id: stringid} (${job: Schema.Struct.ReadonlySide<
{
readonly id: Schema.String
readonly kind: Schema.String
},
"Type"
>
(parameter) job: {
id: string;
kind: string;
}
job.kind: stringkind})`),
autoStart?: boolean | undefinedWhen false, worker fibers are not forked until
QueueHandleApi.start
runs. Enqueue still succeeds; items accumulate until workers exist.
pause / resume update the latch before or after start — workers observe it once forked.
autoStart: true,
}),
),
import EffectEffect.const scoped: <A, E, R>(
self: Effect<A, E, R>
) => Effect<A, E, Exclude<R, Scope>>
Runs an effect with a scope that closes when the effect completes.
When to use
Use to acquire scoped resources for the duration of a single workflow.
Details
Finalizers for resources acquired inside the workflow run as soon as the
workflow completes, whether by success, failure, or interruption.
Example (Running a scoped acquisition)
import { Console, Effect } from "effect"
const resource = Effect.acquireRelease(
Console.log("Acquiring resource").pipe(Effect.as("resource")),
() => Console.log("Releasing resource")
)
const program = Effect.scoped(
Effect.gen(function*() {
const res = yield* resource
yield* Console.log(`Using ${res}`)
return res
})
)
Effect.runFork(program)
// Output: "Acquiring resource"
// Output: "Using resource"
// Output: "Releasing resource"
scoped,
),
)