Layer.Layer<Worker.WorkerPlatform, never, never>Provides the Node WorkerPlatform for worker_threads workers and child
process workers, wiring messages, errors, and exits into Effect workers and
terminating the worker if graceful shutdown times out.
export const const layerPlatform: Layer.Layer<Worker.WorkerPlatform>const layerPlatform: {
build: (memoMap: MemoMap, scope: Scope.Scope) => Effect<Context.Context<WorkerPlatform>, never, 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; <…;
}
Provides the Node WorkerPlatform for worker_threads workers and child
process workers, wiring messages, errors, and exits into Effect workers and
terminating the worker if graceful shutdown times out.
layerPlatform: import LayerLayer.interface Layer<in ROut, out E = never, out RIn = never>A Layer describes how to build one or more services for dependency injection.
When to use
Use to model construction of application services for dependency injection,
especially when services have dependencies, can fail during construction, or
need scoped setup and release.
Details
A Layer<ROut, E, RIn> represents ROut as the services this layer
provides, E as the possible errors during layer construction, and RIn as
the services this layer requires as dependencies.
Layer<import WorkerWorker.class WorkerPlatformclass WorkerPlatform {
key: Identifier;
Service: {
spawn: <O = unknown, I = unknown>(id: number) => Effect.Effect<Worker<O, I>, WorkerError, Spawner>;
};
}
Service that spawns effect Worker instances for numeric worker ids using
the configured Spawner.
WorkerPlatform> = import LayerLayer.const succeed: {
<I, S>(service: Context.Key<I, S>): (
resource: S
) => Layer<I>
<I, S>(
service: Context.Key<I, S>,
resource: Types.NoInfer<S>
): Layer<I>
}
Constructs a layer that provides a single service from an already available
value.
When to use
Use when you need a Layer that provides a service from an already
constructed implementation without effectful acquisition.
Example (Creating a layer from a service implementation)
import { Context, Effect, Layer } from "effect"
class Database extends Context.Service<Database, {
readonly query: (sql: string) => Effect.Effect<string>
}>()("Database") {}
const DatabaseLive = Layer.succeed(Database, {
query: Effect.fn("Database.query")((sql: string) => Effect.succeed(`Query result: ${sql}`))
})
succeed(import WorkerWorker.class WorkerPlatformclass WorkerPlatform {
key: Identifier;
Service: {
spawn: <O = unknown, I = unknown>(id: number) => Effect.Effect<Worker<O, I>, WorkerError, Spawner>;
};
of: (this: void, self: { readonly spawn: <O = unknown, I = unknown>(id: number) => Effect.Effect<Worker.Worker<O, I>, WorkerError, Worker.Spawner> }) => { readonly spawn: <O = unknown, I = unknown>(id: number) => Effect.Effect<Worker.Worker<O,…;
context: (self: { readonly spawn: <O = unknown, I = unknown>(id: number) => Effect.Effect<Worker.Worker<O, I>, WorkerError, Worker.Spawner> }) => Context<Worker.WorkerPlatform>;
use: (f: (service: { readonly spawn: <O = unknown, I = unknown>(id: number) => Effect.Effect<Worker.Worker<O, I>, WorkerError, Worker.Spawner> }) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, Worker.WorkerPlatform | R>;
useSync: (f: (service: { readonly spawn: <O = unknown, I = unknown>(id: number) => Effect.Effect<Worker.Worker<O, I>, WorkerError, Worker.Spawner> }) => A) => Effect.Effect<A, never, Worker.WorkerPlatform>;
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;
}
Service that spawns effect Worker instances for numeric worker ids using
the configured Spawner.
WorkerPlatform)(
import WorkerWorker.const makePlatform: <W>() => <
P extends {
readonly postMessage: (
message: any,
transfers?: any | undefined
) => void
}
>(options: {
readonly setup: (options: {
readonly worker: W
readonly scope: Scope.Scope
}) => Effect.Effect<P, WorkerError>
readonly listen: (options: {
readonly port: P
readonly emit: (data: any) => void
readonly deferred: Deferred.Deferred<
never,
WorkerError
>
readonly scope: Scope.Scope
}) => Effect.Effect<void>
}) => Worker.WorkerPlatform["Service"]
Creates a WorkerPlatform from platform-specific setup and listen hooks,
buffering sent messages until the worker is ready and scoping port cleanup to
the worker run.
makePlatform<import WorkerThreadsWorkerThreads.type WorkerThreads.Worker = /*unresolved*/ anyWorker | import ChildProcessChildProcess.type ChildProcess.ChildProcess = /*unresolved*/ anyChildProcess>()({
setup: ({
scope,
worker,
}: {
readonly worker: any
readonly scope: Scope.Scope
}) => Effect.Effect<
{
postMessage(msg: any, t?: any): void
kill: () => any
worker: any
},
never,
never
>
setup({ scope: Scope.Scope(parameter) scope: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
}
scope, worker: anyworker }) {
const const exitDeferred: Deferred.Deferred<
void,
WorkerError
>
const exitDeferred: {
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; <…;
}
exitDeferred = import DeferredDeferred.const makeUnsafe: <
A,
E = never
>() => Deferred<A, E>
Creates an empty Deferred synchronously outside the Effect runtime.
When to use
Use to allocate a Deferred synchronously when direct allocation outside
Effect is required.
Example (Creating a Deferred unsafely)
import { Deferred } from "effect"
const deferred = Deferred.makeUnsafe<number>()
console.log(deferred)
makeUnsafe<void, class WorkerErrorclass WorkerError {
message: string;
_tag: 'WorkerError';
reason: WorkerSpawnError | WorkerSendError | WorkerReceiveError | WorkerUnknownError;
name: string;
stack: string;
cause: unknown;
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;
}
Error raised by worker APIs, wrapping a specific WorkerErrorReason and
exposing its message and cause.
WorkerError>()
const const thing: {
postMessage(msg: any, t?: any): void
kill: () => any
worker: any
}
thing = "postMessage" in worker: anyworker ?
{
function postMessage(msg: any, t?: any): voidpostMessage(msg: anymsg: any, t: anyt?: any) {
worker: anyworker.postMessage(msg: anymsg, t: anyt)
},
kill: () => anykill: () => worker: anyworker.terminate(),
worker: anyworker
} :
{
function postMessage(msg: any, _?: any): voidpostMessage(msg: anymsg: any, _: any_?: any) {
worker: anyworker.send(msg: anymsg)
},
kill: () => anykill: () => worker: anyworker.kill("SIGKILL"),
worker: anyworker
}
worker: anyworker.on("exit", () => {
import DeferredDeferred.const doneUnsafe: <A, E>(
self: Deferred<A, E>,
effect: Effect<A, E>
) => boolean
Attempts to complete the Deferred synchronously with the specified
completion effect.
When to use
Use to complete a Deferred synchronously in low-level code that already has
the completion effect.
Details
This mutates the Deferred directly and should be reserved for low-level
code; prefer the effectful completion APIs when possible. Returns true if
this call completed the Deferred, or false if it was already completed.
Example (Completing a Deferred unsafely)
import { Deferred, Effect } from "effect"
const deferred = Deferred.makeUnsafe<number>()
const success = Deferred.doneUnsafe(deferred, Effect.succeed(42))
console.log(success) // true
doneUnsafe(const exitDeferred: Deferred.Deferred<
void,
WorkerError
>
const exitDeferred: {
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; <…;
}
exitDeferred, import ExitExit.const void: Exit.Exit<void, never>Provides a pre-allocated successful Exit with a void value.
When to use
Use when you need a shared successful Exit with no meaningful value.
Details
Equivalent to Exit.succeed(undefined) but shared as a single instance,
avoiding allocation for a common case.
Example (Referencing the void Exit)
import { Exit } from "effect"
const exit = Exit.void
console.log(Exit.isSuccess(exit)) // true
void)
})
return import EffectEffect.const as: {
<B>(value: B): <A, E, R>(
self: Effect<A, E, R>
) => Effect<B, E, R>
<A, E, R, B>(
self: Effect<A, E, R>,
value: B
): Effect<B, E, R>
}
Replaces the value inside an effect with a constant value.
When to use
Use to replace a successful value with a constant while preserving failures
and requirements.
Details
as allows you to ignore the original value inside an effect and
replace it with a new constant value.
Example (Replacing a success value)
import { Effect, pipe } from "effect"
// Replaces the value 5 with the constant "new value"
const program = pipe(Effect.succeed(5), Effect.as("new value"))
Effect.runPromise(program).then(console.log)
// Output: "new value"
as(
import ScopeScope.const addFinalizer: (
scope: Scope,
finalizer: Effect<unknown>
) => Effect<void>
Registers a finalizer effect on a scope.
Details
If the scope is open, the finalizer runs when the scope closes, regardless of
whether the scope closes successfully or with an error. If the scope is
already closed, the finalizer runs immediately.
Example (Adding finalizers)
import { Console, Effect, Exit, Scope } from "effect"
const program = Effect.gen(function*() {
const scope = yield* Scope.make()
// Add simple finalizers
yield* Scope.addFinalizer(scope, Console.log("Cleanup task 1"))
yield* Scope.addFinalizer(scope, Console.log("Cleanup task 2"))
yield* Scope.addFinalizer(scope, Effect.log("Cleanup task 3"))
// Do some work
yield* Console.log("Doing work...")
// Close the scope
yield* Scope.close(scope, Exit.void)
})
addFinalizer(
scope: Scope.Scope(parameter) scope: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
}
scope,
import EffectEffect.const suspend: <A, E, R>(
effect: LazyArg<Effect<A, E, R>>
) => Effect<A, E, R>
Creates an Effect lazily, delaying construction until it is needed.
When to use
Use when you need to defer the evaluation of an effect until it is required.
Details
suspend takes a thunk that represents an effect and delays creating it
until the suspended effect is evaluated. This is useful for optimizing
expensive computations, managing circular dependencies such as recursive
functions, and helping TypeScript unify return types when branches construct
different effects. Any side effects or scoped captures inside the thunk are
re-executed on each invocation.
Example (Lazily evaluating side effects)
import { Effect } from "effect"
let i = 0
const bad = Effect.succeed(i++)
const good = Effect.suspend(() => Effect.succeed(i++))
console.log(Effect.runSync(bad)) // Output: 0
console.log(Effect.runSync(bad)) // Output: 0
console.log(Effect.runSync(good)) // Output: 1
console.log(Effect.runSync(good)) // Output: 2
Example (Suspending recursive Fibonacci evaluation)
import { Effect } from "effect"
const blowsUp = (n: number): Effect.Effect<number> =>
n < 2
? Effect.succeed(1)
: Effect.zipWith(blowsUp(n - 1), blowsUp(n - 2), (a, b) => a + b)
// console.log(Effect.runSync(blowsUp(32)))
// crash: JavaScript heap out of memory
const allGood = (n: number): Effect.Effect<number> =>
n < 2
? Effect.succeed(1)
: Effect.zipWith(
Effect.suspend(() => allGood(n - 1)),
Effect.suspend(() => allGood(n - 2)),
(a, b) => a + b
)
console.log(Effect.runSync(allGood(32)))
// Output: 3524578
Example (Helping TypeScript infer recursive effect types)
import { Effect } from "effect"
// Without suspend, TypeScript may struggle with type inference.
// Inferred type:
// (a: number, b: number) =>
// Effect<never, Error, never> | Effect<number, never, never>
const withoutSuspend = (a: number, b: number) =>
b === 0
? Effect.fail(new Error("Cannot divide by zero"))
: Effect.succeed(a / b)
// Using suspend to unify return types.
// Inferred type:
// (a: number, b: number) => Effect<number, Error, never>
const withSuspend = (a: number, b: number) =>
Effect.suspend(() =>
b === 0
? Effect.fail(new Error("Cannot divide by zero"))
: Effect.succeed(a / b)
)
suspend(() => {
const thing: {
postMessage(msg: any, t?: any): void
kill: () => any
worker: any
}
thing.function postMessage(msg: any, t?: any): voidpostMessage([1])
return import DeferredDeferred.await<A, E>(self: Deferred<A, E>): Effect<A, E>Retrieves the value of the Deferred, suspending the fiber running the
workflow until the result is available.
When to use
Use to wait for a Deferred to be completed and resume with its success,
failure, defect, or interruption.
Details
Awaiters observe the completion effect stored in the Deferred.
Example (Awaiting a Deferred value)
import { Deferred, Effect } from "effect"
const program = Effect.gen(function*() {
const deferred = yield* Deferred.make<number>()
yield* Deferred.succeed(deferred, 42)
const value = yield* Deferred.await(deferred)
console.log(value) // 42
})
await(const exitDeferred: Deferred.Deferred<
void,
WorkerError
>
const exitDeferred: {
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; <…;
}
exitDeferred)
}).Pipeable.pipe<Effect.Effect<void, WorkerError, never>, Effect.Effect<void, WorkerError | TimeoutError, never>, Effect.Effect<any, never, never>>(this: Effect.Effect<void, WorkerError, never>, ab: (_: Effect.Effect<void, WorkerError, never>) => Effect.Effect<void, WorkerError | TimeoutError, never>, bc: (_: Effect.Effect<void, WorkerError | TimeoutError, never>) => Effect.Effect<any, never, never>): Effect.Effect<...> (+21 overloads)pipe(
import EffectEffect.const timeout: {
(duration: Duration.Input): <A, E, R>(
self: Effect<A, E, R>
) => Effect<A, E | Cause.TimeoutError, R>
<A, E, R>(
self: Effect<A, E, R>,
duration: Duration.Input
): Effect<A, E | Cause.TimeoutError, R>
}
Adds a time limit to an effect, triggering a timeout if the effect exceeds
the duration.
When to use
Use when you need a timeout of an Effect to be represented as a typed
failure.
Details
The timeout function allows you to specify a time limit for an
effect's execution. If the effect does not complete within the given time, a
TimeoutException is raised. This can be useful for controlling how long
your program waits for a task to finish, ensuring that it doesn't hang
indefinitely if the task takes too long.
Gotchas
If the timeout wins, the source effect is interrupted.
Example (Failing when work takes too long)
import { Effect } from "effect"
const task = Effect.gen(function*() {
console.log("Start processing...")
yield* Effect.sleep("2 seconds") // Simulates a delay in processing
console.log("Processing complete.")
return "Result"
})
// Output will show a TimeoutException as the task takes longer
// than the specified timeout duration
const timedEffect = task.pipe(Effect.timeout("1 second"))
Effect.runPromiseExit(timedEffect).then(console.log)
// Output:
// Start processing...
// {
// _id: 'Exit',
// _tag: 'Failure',
// cause: {
// _id: 'Cause',
// _tag: 'Fail',
// failure: { _tag: 'TimeoutException' }
// }
// }
timeout(5000),
import EffectEffect.const catchCause: {
<E, A2, E2, R2>(
f: (
cause: Cause.Cause<E>
) => Effect<A2, E2, R2>
): <A, R>(
self: Effect<A, E, R>
) => Effect<A2 | A, E2, R2 | R>
<A, E, R, A2, E2, R2>(
self: Effect<A, E, R>,
f: (
cause: Cause.Cause<E>
) => Effect<A2, E2, R2>
): Effect<A | A2, E2, R | R2>
}
Handles both recoverable and unrecoverable errors by providing a recovery
effect.
When to use
Use when you need to recover from an Effect by inspecting the full Cause,
including recoverable failures, defects, and interruptions, instead of only
the typed error value.
Details
When to Recover from Defects:
Defects are unexpected errors that typically shouldn't be recovered from, as
they often indicate serious issues. However, in some cases, such as
dynamically loaded plugins, controlled recovery might be needed.
Example (Recovering from full failure causes)
import { Cause, Console, Effect } from "effect"
// An effect that might fail in different ways
const program = Effect.die("Something went wrong")
// Recover from any cause (including defects)
const recovered = Effect.catchCause(program, (cause) => {
if (Cause.hasDies(cause)) {
return Console.log("Caught defect").pipe(
Effect.as("Recovered from defect")
)
}
return Effect.succeed("Unknown error")
})
catchCause(() => import EffectEffect.const sync: <A>(
thunk: LazyArg<A>
) => Effect<A>
Creates an Effect that represents a synchronous side-effectful computation.
When to use
Use when you need to wrap a synchronous side-effectful operation that is not
expected to throw.
Details
The provided function is evaluated lazily when the effect runs.
Gotchas
The function must not throw. If it throws, the thrown value is treated as a
defect, not as a typed failure. Use try when throwing is expected.
Example (Capturing synchronous logging in an Effect)
import { Effect } from "effect"
const log = (message: string) =>
Effect.sync(() => {
console.log(message) // side effect
})
// ┌─── Effect<void, never, never>
// ▼
const program = log("Hello, World!")
sync(() => const thing: {
postMessage(msg: any, t?: any): void
kill: () => any
worker: any
}
thing.kill: () => anykill()))
)
),
const thing: {
postMessage(msg: any, t?: any): void
kill: () => any
worker: any
}
thing
)
},
listen: ({
deferred,
emit,
port,
}: {
readonly port: {
postMessage(msg: any, t?: any): void
kill: () => any
worker: any
}
readonly emit: (data: any) => void
readonly deferred: Deferred.Deferred<
never,
WorkerError
>
readonly scope: Scope.Scope
}) => Effect.Effect<void, never, never>
listen({ deferred: Deferred.Deferred<never, WorkerError>(parameter) 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, emit: (data: any) => voidemit, port: {
postMessage(msg: any, t?: any): void
kill: () => any
worker: any
}
port }) {
port: {
postMessage(msg: any, t?: any): void
kill: () => any
worker: any
}
port.worker: anyworker.on("message", (message: anymessage) => {
emit: (data: any) => voidemit(message: anymessage)
})
port: {
postMessage(msg: any, t?: any): void
kill: () => any
worker: any
}
port.worker: anyworker.on("messageerror", (cause: anycause) => {
import DeferredDeferred.const doneUnsafe: <A, E>(
self: Deferred<A, E>,
effect: Effect<A, E>
) => boolean
Attempts to complete the Deferred synchronously with the specified
completion effect.
When to use
Use to complete a Deferred synchronously in low-level code that already has
the completion effect.
Details
This mutates the Deferred directly and should be reserved for low-level
code; prefer the effectful completion APIs when possible. Returns true if
this call completed the Deferred, or false if it was already completed.
Example (Completing a Deferred unsafely)
import { Deferred, Effect } from "effect"
const deferred = Deferred.makeUnsafe<number>()
const success = Deferred.doneUnsafe(deferred, Effect.succeed(42))
console.log(success) // true
doneUnsafe(
deferred: Deferred.Deferred<never, WorkerError>(parameter) 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,
new new WorkerError(props: {
readonly reason: WorkerErrorReason;
}): WorkerError
(alias) new WorkerError(props: {
readonly reason: WorkerErrorReason;
}): {
Type: Self;
Encoded: S["Encoded"];
DecodingServices: S["DecodingServices"];
EncodingServices: S["EncodingServices"];
Iso: S["Iso"];
identifier: string;
fields: S["fields"];
mapFields: (f: (fields: { readonly _tag: tag<'WorkerError'>; readonly reason: Union<[typeof WorkerSpawnError, typeof WorkerSendError, typeof WorkerReceiveError, typeof WorkerUnknownError]> }) => To, options?: { readonly unsafePreserveChecks?: boolean…;
extend: (identifier: string) => { (fields: NewFields, annotations?: Annotations.Declaration<Extended, readonly [Struct<{ [K in keyof { [K in keyof (('_tag' | 'reason') & keyof NewFields extends never ? { readonly _tag: tag<'WorkerError'>; readonly…;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Annotations.Bottom<WorkerError, readonly [Struct<{ readonly _tag: tag<'WorkerError'>; readonly reason: Union<[typeof WorkerSpawnError, typeof WorkerSendError, typeof WorkerReceiveError, typeof WorkerUnknownError]> }>]>) => de…;
annotateKey: (annotations: Annotations.Key<WorkerError>) => decodeTo<declareConstructor<WorkerError, Struct.ReadonlySide<{ readonly _tag: tag<'WorkerError'>; readonly reason: Union<[typeof WorkerSpawnError, typeof WorkerSendError, typeof WorkerReceiveE…;
check: (checks_0: Check<WorkerError>, ...checks: Array<Check<WorkerError>>) => decodeTo<declareConstructor<WorkerError, Struct.ReadonlySide<{ readonly _tag: tag<'WorkerError'>; readonly reason: Union<[typeof WorkerSpawnError, typeof WorkerSendErr…;
rebuild: (ast: Declaration) => decodeTo<declareConstructor<WorkerError, Struct.ReadonlySide<{ readonly _tag: tag<'WorkerError'>; readonly reason: Union<[typeof WorkerSpawnError, typeof WorkerSendError, typeof WorkerReceiveError, typeof WorkerUnknow…;
make: (input: { readonly reason: WorkerSpawnError | WorkerSendError | WorkerReceiveError | WorkerUnknownError; readonly _tag?: 'WorkerError' | undefined }, options?: MakeOptions) => WorkerError;
makeOption: (input: { readonly reason: WorkerSpawnError | WorkerSendError | WorkerReceiveError | WorkerUnknownError; readonly _tag?: 'WorkerError' | undefined }, options?: MakeOptions) => Option_.Option<WorkerError>;
makeEffect: (input: { readonly reason: WorkerSpawnError | WorkerSendError | WorkerReceiveError | WorkerUnknownError; readonly _tag?: 'WorkerError' | undefined }, options?: MakeOptions) => Effect.Effect<WorkerError, 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; <…;
}
Error raised by worker APIs, wrapping a specific WorkerErrorReason and
exposing its message and cause.
WorkerError({
reason: WorkerErrorReason(property) reason: {
_tag: 'WorkerReceiveError';
message: string;
cause: unknown;
name: string;
stack: string;
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;
}
reason: new new WorkerReceiveError(props: {
readonly message: string;
readonly _tag?: "WorkerReceiveError" | undefined;
readonly cause?: unknown;
}, options?: MakeOptions | undefined): WorkerReceiveError
(alias) new WorkerReceiveError(props: {
readonly message: string;
readonly _tag?: "WorkerReceiveError" | undefined;
readonly cause?: unknown;
}, options?: MakeOptions | undefined): {
Type: Self;
Encoded: S["Encoded"];
DecodingServices: S["DecodingServices"];
EncodingServices: S["EncodingServices"];
Iso: S["Iso"];
identifier: string;
fields: S["fields"];
mapFields: (f: (fields: { readonly _tag: tag<'WorkerReceiveError'>; readonly message: String; readonly cause: optional<Defect> }) => To, options?: { readonly unsafePreserveChecks?: boolean | undefined } | undefined) => Struct<{ [K in keyof Readonly<T…;
extend: (identifier: string) => { (fields: NewFields, annotations?: Annotations.Declaration<Extended, readonly [Struct<{ [K in keyof { [K in keyof (('_tag' | 'cause' | 'message') & keyof NewFields extends never ? { readonly _tag: tag<'WorkerReceiv…;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Annotations.Bottom<WorkerReceiveError, readonly [Struct<{ readonly _tag: tag<'WorkerReceiveError'>; readonly message: String; readonly cause: optional<Defect> }>]>) => decodeTo<declareConstructor<WorkerReceiveError, { readonl…;
annotateKey: (annotations: Annotations.Key<WorkerReceiveError>) => decodeTo<declareConstructor<WorkerReceiveError, { readonly _tag: 'WorkerReceiveError'; readonly message: string; readonly cause?: Json | undefined }, readonly [Struct<{ readonly _tag: t…;
check: (checks_0: Check<WorkerReceiveError>, ...checks: Array<Check<WorkerReceiveError>>) => decodeTo<declareConstructor<WorkerReceiveError, { readonly _tag: 'WorkerReceiveError'; readonly message: string; readonly cause?: Json | undefined }, rea…;
rebuild: (ast: Declaration) => decodeTo<declareConstructor<WorkerReceiveError, { readonly _tag: 'WorkerReceiveError'; readonly message: string; readonly cause?: Json | undefined }, readonly [Struct<{ readonly _tag: tag<'WorkerReceiveError'>; readon…;
make: (input: { readonly message: string; readonly _tag?: 'WorkerReceiveError' | undefined; readonly cause?: unknown }, options?: MakeOptions) => WorkerReceiveError;
makeOption: (input: { readonly message: string; readonly _tag?: 'WorkerReceiveError' | undefined; readonly cause?: unknown }, options?: MakeOptions) => Option_.Option<WorkerReceiveError>;
makeEffect: (input: { readonly message: string; readonly _tag?: 'WorkerReceiveError' | undefined; readonly cause?: unknown }, options?: MakeOptions) => Effect.Effect<WorkerReceiveError, 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; <…;
}
Worker error reason for failures while receiving or handling a message from a
worker.
WorkerReceiveError({
message: stringmessage: "An messageerror event was emitted",
cause?: unknowncause
})
})
)
})
port: {
postMessage(msg: any, t?: any): void
kill: () => any
worker: any
}
port.worker: anyworker.on("error", (cause: anycause) => {
import DeferredDeferred.const doneUnsafe: <A, E>(
self: Deferred<A, E>,
effect: Effect<A, E>
) => boolean
Attempts to complete the Deferred synchronously with the specified
completion effect.
When to use
Use to complete a Deferred synchronously in low-level code that already has
the completion effect.
Details
This mutates the Deferred directly and should be reserved for low-level
code; prefer the effectful completion APIs when possible. Returns true if
this call completed the Deferred, or false if it was already completed.
Example (Completing a Deferred unsafely)
import { Deferred, Effect } from "effect"
const deferred = Deferred.makeUnsafe<number>()
const success = Deferred.doneUnsafe(deferred, Effect.succeed(42))
console.log(success) // true
doneUnsafe(
deferred: Deferred.Deferred<never, WorkerError>(parameter) 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,
new new WorkerError(props: {
readonly reason: WorkerErrorReason;
}): WorkerError
(alias) new WorkerError(props: {
readonly reason: WorkerErrorReason;
}): {
Type: Self;
Encoded: S["Encoded"];
DecodingServices: S["DecodingServices"];
EncodingServices: S["EncodingServices"];
Iso: S["Iso"];
identifier: string;
fields: S["fields"];
mapFields: (f: (fields: { readonly _tag: tag<'WorkerError'>; readonly reason: Union<[typeof WorkerSpawnError, typeof WorkerSendError, typeof WorkerReceiveError, typeof WorkerUnknownError]> }) => To, options?: { readonly unsafePreserveChecks?: boolean…;
extend: (identifier: string) => { (fields: NewFields, annotations?: Annotations.Declaration<Extended, readonly [Struct<{ [K in keyof { [K in keyof (('_tag' | 'reason') & keyof NewFields extends never ? { readonly _tag: tag<'WorkerError'>; readonly…;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Annotations.Bottom<WorkerError, readonly [Struct<{ readonly _tag: tag<'WorkerError'>; readonly reason: Union<[typeof WorkerSpawnError, typeof WorkerSendError, typeof WorkerReceiveError, typeof WorkerUnknownError]> }>]>) => de…;
annotateKey: (annotations: Annotations.Key<WorkerError>) => decodeTo<declareConstructor<WorkerError, Struct.ReadonlySide<{ readonly _tag: tag<'WorkerError'>; readonly reason: Union<[typeof WorkerSpawnError, typeof WorkerSendError, typeof WorkerReceiveE…;
check: (checks_0: Check<WorkerError>, ...checks: Array<Check<WorkerError>>) => decodeTo<declareConstructor<WorkerError, Struct.ReadonlySide<{ readonly _tag: tag<'WorkerError'>; readonly reason: Union<[typeof WorkerSpawnError, typeof WorkerSendErr…;
rebuild: (ast: Declaration) => decodeTo<declareConstructor<WorkerError, Struct.ReadonlySide<{ readonly _tag: tag<'WorkerError'>; readonly reason: Union<[typeof WorkerSpawnError, typeof WorkerSendError, typeof WorkerReceiveError, typeof WorkerUnknow…;
make: (input: { readonly reason: WorkerSpawnError | WorkerSendError | WorkerReceiveError | WorkerUnknownError; readonly _tag?: 'WorkerError' | undefined }, options?: MakeOptions) => WorkerError;
makeOption: (input: { readonly reason: WorkerSpawnError | WorkerSendError | WorkerReceiveError | WorkerUnknownError; readonly _tag?: 'WorkerError' | undefined }, options?: MakeOptions) => Option_.Option<WorkerError>;
makeEffect: (input: { readonly reason: WorkerSpawnError | WorkerSendError | WorkerReceiveError | WorkerUnknownError; readonly _tag?: 'WorkerError' | undefined }, options?: MakeOptions) => Effect.Effect<WorkerError, 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; <…;
}
Error raised by worker APIs, wrapping a specific WorkerErrorReason and
exposing its message and cause.
WorkerError({
reason: WorkerErrorReason(property) reason: {
_tag: 'WorkerReceiveError';
message: string;
cause: unknown;
name: string;
stack: string;
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;
}
reason: new new WorkerReceiveError(props: {
readonly message: string;
readonly _tag?: "WorkerReceiveError" | undefined;
readonly cause?: unknown;
}, options?: MakeOptions | undefined): WorkerReceiveError
(alias) new WorkerReceiveError(props: {
readonly message: string;
readonly _tag?: "WorkerReceiveError" | undefined;
readonly cause?: unknown;
}, options?: MakeOptions | undefined): {
Type: Self;
Encoded: S["Encoded"];
DecodingServices: S["DecodingServices"];
EncodingServices: S["EncodingServices"];
Iso: S["Iso"];
identifier: string;
fields: S["fields"];
mapFields: (f: (fields: { readonly _tag: tag<'WorkerReceiveError'>; readonly message: String; readonly cause: optional<Defect> }) => To, options?: { readonly unsafePreserveChecks?: boolean | undefined } | undefined) => Struct<{ [K in keyof Readonly<T…;
extend: (identifier: string) => { (fields: NewFields, annotations?: Annotations.Declaration<Extended, readonly [Struct<{ [K in keyof { [K in keyof (('_tag' | 'cause' | 'message') & keyof NewFields extends never ? { readonly _tag: tag<'WorkerReceiv…;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Annotations.Bottom<WorkerReceiveError, readonly [Struct<{ readonly _tag: tag<'WorkerReceiveError'>; readonly message: String; readonly cause: optional<Defect> }>]>) => decodeTo<declareConstructor<WorkerReceiveError, { readonl…;
annotateKey: (annotations: Annotations.Key<WorkerReceiveError>) => decodeTo<declareConstructor<WorkerReceiveError, { readonly _tag: 'WorkerReceiveError'; readonly message: string; readonly cause?: Json | undefined }, readonly [Struct<{ readonly _tag: t…;
check: (checks_0: Check<WorkerReceiveError>, ...checks: Array<Check<WorkerReceiveError>>) => decodeTo<declareConstructor<WorkerReceiveError, { readonly _tag: 'WorkerReceiveError'; readonly message: string; readonly cause?: Json | undefined }, rea…;
rebuild: (ast: Declaration) => decodeTo<declareConstructor<WorkerReceiveError, { readonly _tag: 'WorkerReceiveError'; readonly message: string; readonly cause?: Json | undefined }, readonly [Struct<{ readonly _tag: tag<'WorkerReceiveError'>; readon…;
make: (input: { readonly message: string; readonly _tag?: 'WorkerReceiveError' | undefined; readonly cause?: unknown }, options?: MakeOptions) => WorkerReceiveError;
makeOption: (input: { readonly message: string; readonly _tag?: 'WorkerReceiveError' | undefined; readonly cause?: unknown }, options?: MakeOptions) => Option_.Option<WorkerReceiveError>;
makeEffect: (input: { readonly message: string; readonly _tag?: 'WorkerReceiveError' | undefined; readonly cause?: unknown }, options?: MakeOptions) => Effect.Effect<WorkerReceiveError, 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; <…;
}
Worker error reason for failures while receiving or handling a message from a
worker.
WorkerReceiveError({
message: stringmessage: "An error event was emitted",
cause?: unknowncause
})
})
)
})
port: {
postMessage(msg: any, t?: any): void
kill: () => any
worker: any
}
port.worker: anyworker.on("exit", (code: anycode) => {
import DeferredDeferred.const doneUnsafe: <A, E>(
self: Deferred<A, E>,
effect: Effect<A, E>
) => boolean
Attempts to complete the Deferred synchronously with the specified
completion effect.
When to use
Use to complete a Deferred synchronously in low-level code that already has
the completion effect.
Details
This mutates the Deferred directly and should be reserved for low-level
code; prefer the effectful completion APIs when possible. Returns true if
this call completed the Deferred, or false if it was already completed.
Example (Completing a Deferred unsafely)
import { Deferred, Effect } from "effect"
const deferred = Deferred.makeUnsafe<number>()
const success = Deferred.doneUnsafe(deferred, Effect.succeed(42))
console.log(success) // true
doneUnsafe(
deferred: Deferred.Deferred<never, WorkerError>(parameter) 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,
new new WorkerError(props: {
readonly reason: WorkerErrorReason;
}): WorkerError
(alias) new WorkerError(props: {
readonly reason: WorkerErrorReason;
}): {
Type: Self;
Encoded: S["Encoded"];
DecodingServices: S["DecodingServices"];
EncodingServices: S["EncodingServices"];
Iso: S["Iso"];
identifier: string;
fields: S["fields"];
mapFields: (f: (fields: { readonly _tag: tag<'WorkerError'>; readonly reason: Union<[typeof WorkerSpawnError, typeof WorkerSendError, typeof WorkerReceiveError, typeof WorkerUnknownError]> }) => To, options?: { readonly unsafePreserveChecks?: boolean…;
extend: (identifier: string) => { (fields: NewFields, annotations?: Annotations.Declaration<Extended, readonly [Struct<{ [K in keyof { [K in keyof (('_tag' | 'reason') & keyof NewFields extends never ? { readonly _tag: tag<'WorkerError'>; readonly…;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Annotations.Bottom<WorkerError, readonly [Struct<{ readonly _tag: tag<'WorkerError'>; readonly reason: Union<[typeof WorkerSpawnError, typeof WorkerSendError, typeof WorkerReceiveError, typeof WorkerUnknownError]> }>]>) => de…;
annotateKey: (annotations: Annotations.Key<WorkerError>) => decodeTo<declareConstructor<WorkerError, Struct.ReadonlySide<{ readonly _tag: tag<'WorkerError'>; readonly reason: Union<[typeof WorkerSpawnError, typeof WorkerSendError, typeof WorkerReceiveE…;
check: (checks_0: Check<WorkerError>, ...checks: Array<Check<WorkerError>>) => decodeTo<declareConstructor<WorkerError, Struct.ReadonlySide<{ readonly _tag: tag<'WorkerError'>; readonly reason: Union<[typeof WorkerSpawnError, typeof WorkerSendErr…;
rebuild: (ast: Declaration) => decodeTo<declareConstructor<WorkerError, Struct.ReadonlySide<{ readonly _tag: tag<'WorkerError'>; readonly reason: Union<[typeof WorkerSpawnError, typeof WorkerSendError, typeof WorkerReceiveError, typeof WorkerUnknow…;
make: (input: { readonly reason: WorkerSpawnError | WorkerSendError | WorkerReceiveError | WorkerUnknownError; readonly _tag?: 'WorkerError' | undefined }, options?: MakeOptions) => WorkerError;
makeOption: (input: { readonly reason: WorkerSpawnError | WorkerSendError | WorkerReceiveError | WorkerUnknownError; readonly _tag?: 'WorkerError' | undefined }, options?: MakeOptions) => Option_.Option<WorkerError>;
makeEffect: (input: { readonly reason: WorkerSpawnError | WorkerSendError | WorkerReceiveError | WorkerUnknownError; readonly _tag?: 'WorkerError' | undefined }, options?: MakeOptions) => Effect.Effect<WorkerError, 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; <…;
}
Error raised by worker APIs, wrapping a specific WorkerErrorReason and
exposing its message and cause.
WorkerError({
reason: WorkerErrorReason(property) reason: {
_tag: 'WorkerReceiveError';
message: string;
cause: unknown;
name: string;
stack: string;
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;
}
reason: new new WorkerReceiveError(props: {
readonly message: string;
readonly _tag?: "WorkerReceiveError" | undefined;
readonly cause?: unknown;
}, options?: MakeOptions | undefined): WorkerReceiveError
(alias) new WorkerReceiveError(props: {
readonly message: string;
readonly _tag?: "WorkerReceiveError" | undefined;
readonly cause?: unknown;
}, options?: MakeOptions | undefined): {
Type: Self;
Encoded: S["Encoded"];
DecodingServices: S["DecodingServices"];
EncodingServices: S["EncodingServices"];
Iso: S["Iso"];
identifier: string;
fields: S["fields"];
mapFields: (f: (fields: { readonly _tag: tag<'WorkerReceiveError'>; readonly message: String; readonly cause: optional<Defect> }) => To, options?: { readonly unsafePreserveChecks?: boolean | undefined } | undefined) => Struct<{ [K in keyof Readonly<T…;
extend: (identifier: string) => { (fields: NewFields, annotations?: Annotations.Declaration<Extended, readonly [Struct<{ [K in keyof { [K in keyof (('_tag' | 'cause' | 'message') & keyof NewFields extends never ? { readonly _tag: tag<'WorkerReceiv…;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Annotations.Bottom<WorkerReceiveError, readonly [Struct<{ readonly _tag: tag<'WorkerReceiveError'>; readonly message: String; readonly cause: optional<Defect> }>]>) => decodeTo<declareConstructor<WorkerReceiveError, { readonl…;
annotateKey: (annotations: Annotations.Key<WorkerReceiveError>) => decodeTo<declareConstructor<WorkerReceiveError, { readonly _tag: 'WorkerReceiveError'; readonly message: string; readonly cause?: Json | undefined }, readonly [Struct<{ readonly _tag: t…;
check: (checks_0: Check<WorkerReceiveError>, ...checks: Array<Check<WorkerReceiveError>>) => decodeTo<declareConstructor<WorkerReceiveError, { readonly _tag: 'WorkerReceiveError'; readonly message: string; readonly cause?: Json | undefined }, rea…;
rebuild: (ast: Declaration) => decodeTo<declareConstructor<WorkerReceiveError, { readonly _tag: 'WorkerReceiveError'; readonly message: string; readonly cause?: Json | undefined }, readonly [Struct<{ readonly _tag: tag<'WorkerReceiveError'>; readon…;
make: (input: { readonly message: string; readonly _tag?: 'WorkerReceiveError' | undefined; readonly cause?: unknown }, options?: MakeOptions) => WorkerReceiveError;
makeOption: (input: { readonly message: string; readonly _tag?: 'WorkerReceiveError' | undefined; readonly cause?: unknown }, options?: MakeOptions) => Option_.Option<WorkerReceiveError>;
makeEffect: (input: { readonly message: string; readonly _tag?: 'WorkerReceiveError' | undefined; readonly cause?: unknown }, options?: MakeOptions) => Effect.Effect<WorkerReceiveError, 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; <…;
}
Worker error reason for failures while receiving or handling a message from a
worker.
WorkerReceiveError({
message: stringmessage: "The worker has exited with code: " + code: anycode
})
})
)
})
return import EffectEffect.const void: Effect.Effect<void, never, never>(alias) const void: {
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;
}
Returns an effect that succeeds with void.
void
}
})
)