<
R,
E,
App extends Effect.Effect<HttpServerResponse, any, any> = Effect.Effect<
HttpServerResponse,
E,
R
>
>(
httpEffect: Effect.Effect<HttpServerResponse, E, R>,
options: {
readonly scope: Scope.Scope
readonly middleware?:
| Middleware.HttpMiddleware.Applied<App, E, R>
| undefined
}
): Effect.Effect<
(
nodeRequest: Http.IncomingMessage,
nodeResponse: Http.ServerResponse
) => void,
never,
Exclude<Effect.Services<App>, HttpServerRequest | Scope.Scope>
>Creates a Node request event handler for an Effect HTTP application,
injecting a HttpServerRequest and interrupting the request fiber if the
client closes the response before it finishes.
export const const makeHandler: <
R,
E,
App extends Effect.Effect<
HttpServerResponse,
any,
any
> = Effect.Effect<HttpServerResponse, E, R>
>(
httpEffect: Effect.Effect<
HttpServerResponse,
E,
R
>,
options: {
readonly scope: Scope.Scope
readonly middleware?:
| Middleware.HttpMiddleware.Applied<
App,
E,
R
>
| undefined
}
) => Effect.Effect<
(
nodeRequest: Http.IncomingMessage,
nodeResponse: Http.ServerResponse
) => void,
never,
Exclude<
Effect.Services<App>,
HttpServerRequest | Scope.Scope
>
>
Creates a Node request event handler for an Effect HTTP application,
injecting a HttpServerRequest and interrupting the request fiber if the
client closes the response before it finishes.
makeHandler = <
function (type parameter) R in <R, E, App extends Effect.Effect<HttpServerResponse, any, any> = Effect.Effect<HttpServerResponse, E, R>>(httpEffect: Effect.Effect<HttpServerResponse, E, R>, options: {
readonly scope: Scope.Scope;
readonly middleware?: Middleware.HttpMiddleware.Applied<App, E, R> | undefined;
}): Effect.Effect<(nodeRequest: Http.IncomingMessage, nodeResponse: Http.ServerResponse) => void, never, Exclude<Effect.Services<App>, HttpServerRequest | Scope.Scope>>
R,
function (type parameter) E in <R, E, App extends Effect.Effect<HttpServerResponse, any, any> = Effect.Effect<HttpServerResponse, E, R>>(httpEffect: Effect.Effect<HttpServerResponse, E, R>, options: {
readonly scope: Scope.Scope;
readonly middleware?: Middleware.HttpMiddleware.Applied<App, E, R> | undefined;
}): Effect.Effect<(nodeRequest: Http.IncomingMessage, nodeResponse: Http.ServerResponse) => void, never, Exclude<Effect.Services<App>, HttpServerRequest | Scope.Scope>>
E,
function (type parameter) App in <R, E, App extends Effect.Effect<HttpServerResponse, any, any> = Effect.Effect<HttpServerResponse, E, R>>(httpEffect: Effect.Effect<HttpServerResponse, E, R>, options: {
readonly scope: Scope.Scope;
readonly middleware?: Middleware.HttpMiddleware.Applied<App, E, R> | undefined;
}): Effect.Effect<(nodeRequest: Http.IncomingMessage, nodeResponse: Http.ServerResponse) => void, never, Exclude<Effect.Services<App>, HttpServerRequest | Scope.Scope>>
App extends import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<HttpServerResponse, any, any> = import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<HttpServerResponse, function (type parameter) E in <R, E, App extends Effect.Effect<HttpServerResponse, any, any> = Effect.Effect<HttpServerResponse, E, R>>(httpEffect: Effect.Effect<HttpServerResponse, E, R>, options: {
readonly scope: Scope.Scope;
readonly middleware?: Middleware.HttpMiddleware.Applied<App, E, R> | undefined;
}): Effect.Effect<(nodeRequest: Http.IncomingMessage, nodeResponse: Http.ServerResponse) => void, never, Exclude<Effect.Services<App>, HttpServerRequest | Scope.Scope>>
E, function (type parameter) R in <R, E, App extends Effect.Effect<HttpServerResponse, any, any> = Effect.Effect<HttpServerResponse, E, R>>(httpEffect: Effect.Effect<HttpServerResponse, E, R>, options: {
readonly scope: Scope.Scope;
readonly middleware?: Middleware.HttpMiddleware.Applied<App, E, R> | undefined;
}): Effect.Effect<(nodeRequest: Http.IncomingMessage, nodeResponse: Http.ServerResponse) => void, never, Exclude<Effect.Services<App>, HttpServerRequest | Scope.Scope>>
R>
>(
httpEffect: Effect.Effect<HttpServerResponse, E, R>(parameter) httpEffect: {
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;
}
httpEffect: import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<HttpServerResponse, function (type parameter) E in <R, E, App extends Effect.Effect<HttpServerResponse, any, any> = Effect.Effect<HttpServerResponse, E, R>>(httpEffect: Effect.Effect<HttpServerResponse, E, R>, options: {
readonly scope: Scope.Scope;
readonly middleware?: Middleware.HttpMiddleware.Applied<App, E, R> | undefined;
}): Effect.Effect<(nodeRequest: Http.IncomingMessage, nodeResponse: Http.ServerResponse) => void, never, Exclude<Effect.Services<App>, HttpServerRequest | Scope.Scope>>
E, function (type parameter) R in <R, E, App extends Effect.Effect<HttpServerResponse, any, any> = Effect.Effect<HttpServerResponse, E, R>>(httpEffect: Effect.Effect<HttpServerResponse, E, R>, options: {
readonly scope: Scope.Scope;
readonly middleware?: Middleware.HttpMiddleware.Applied<App, E, R> | undefined;
}): Effect.Effect<(nodeRequest: Http.IncomingMessage, nodeResponse: Http.ServerResponse) => void, never, Exclude<Effect.Services<App>, HttpServerRequest | Scope.Scope>>
R>,
options: {
readonly scope: Scope.Scope
readonly middleware?:
| Middleware.HttpMiddleware.Applied<App, E, R>
| undefined
}
options: {
readonly scope: Scope.Scope(property) scope: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
}
scope: import ScopeScope.Scope
readonly middleware?: | Middleware.HttpMiddleware.Applied<App, E, R>
| undefined
middleware?: import MiddlewareMiddleware.HttpMiddleware.interface HttpMiddleware.Applied<A extends Effect.Effect<HttpServerResponse, any, any>, E, R>Callable type representing middleware already specialized to a particular transformed app type.
Applied<function (type parameter) App in <R, E, App extends Effect.Effect<HttpServerResponse, any, any> = Effect.Effect<HttpServerResponse, E, R>>(httpEffect: Effect.Effect<HttpServerResponse, E, R>, options: {
readonly scope: Scope.Scope;
readonly middleware?: Middleware.HttpMiddleware.Applied<App, E, R> | undefined;
}): Effect.Effect<(nodeRequest: Http.IncomingMessage, nodeResponse: Http.ServerResponse) => void, never, Exclude<Effect.Services<App>, HttpServerRequest | Scope.Scope>>
App, function (type parameter) E in <R, E, App extends Effect.Effect<HttpServerResponse, any, any> = Effect.Effect<HttpServerResponse, E, R>>(httpEffect: Effect.Effect<HttpServerResponse, E, R>, options: {
readonly scope: Scope.Scope;
readonly middleware?: Middleware.HttpMiddleware.Applied<App, E, R> | undefined;
}): Effect.Effect<(nodeRequest: Http.IncomingMessage, nodeResponse: Http.ServerResponse) => void, never, Exclude<Effect.Services<App>, HttpServerRequest | Scope.Scope>>
E, function (type parameter) R in <R, E, App extends Effect.Effect<HttpServerResponse, any, any> = Effect.Effect<HttpServerResponse, E, R>>(httpEffect: Effect.Effect<HttpServerResponse, E, R>, options: {
readonly scope: Scope.Scope;
readonly middleware?: Middleware.HttpMiddleware.Applied<App, E, R> | undefined;
}): Effect.Effect<(nodeRequest: Http.IncomingMessage, nodeResponse: Http.ServerResponse) => void, never, Exclude<Effect.Services<App>, HttpServerRequest | Scope.Scope>>
R> | undefined
}
): import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<
(nodeRequest: Http.IncomingMessagenodeRequest: import HttpHttp.type Http.IncomingMessage = /*unresolved*/ anyIncomingMessage, nodeResponse: Http.ServerResponsenodeResponse: import HttpHttp.type Http.ServerResponse = /*unresolved*/ anyServerResponse) => void,
never,
type Exclude<T, U> = T extends U
? never
: T
Exclude from T those types that are assignable to U
Exclude<import EffectEffect.type Services<T> =
T extends Effect.Effect<
infer _A,
infer _E,
infer _R
>
? _R
: never
Extracts the required services type from an Effect.
When to use
Use to derive the context requirements of a generic or inferred Effect
without restating its R type parameter.
Services<function (type parameter) App in <R, E, App extends Effect.Effect<HttpServerResponse, any, any> = Effect.Effect<HttpServerResponse, E, R>>(httpEffect: Effect.Effect<HttpServerResponse, E, R>, options: {
readonly scope: Scope.Scope;
readonly middleware?: Middleware.HttpMiddleware.Applied<App, E, R> | undefined;
}): Effect.Effect<(nodeRequest: Http.IncomingMessage, nodeResponse: Http.ServerResponse) => void, never, Exclude<Effect.Services<App>, HttpServerRequest | Scope.Scope>>
App>, HttpServerRequest | import ScopeScope.Scope>
> => {
const const handled: Effect.Effect<
void,
never,
| Request.HttpServerRequest
| Exclude<R, Scope.Scope>
>
const handled: {
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;
}
handled = import HttpEffectHttpEffect.const toHandled: <E, R, EH, RH>(
self: Effect.Effect<HttpServerResponse, E, R>,
handleResponse: (
request: HttpServerRequest,
response: HttpServerResponse
) => Effect.Effect<unknown, EH, RH>,
middleware?:
| Middleware.HttpMiddleware
| undefined
) => Effect.Effect<
void,
never,
Exclude<R | RH | HttpServerRequest, Scope.Scope>
>
Runs an HTTP server effect, sends the produced response with the supplied handler, and converts failures into HTTP responses.
toHandled(httpEffect: Effect.Effect<HttpServerResponse, E, R>(parameter) httpEffect: {
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;
}
httpEffect, const handleResponse: (
request: HttpServerRequest,
response: HttpServerResponse
) => Effect.Effect<void, HttpServerError>
handleResponse, options: {
readonly scope: Scope.Scope
readonly middleware?:
| Middleware.HttpMiddleware.Applied<App, E, R>
| undefined
}
options.middleware?: | Middleware.HttpMiddleware.Applied<App, E, R>
| undefined
middleware as any)
return import EffectEffect.const withFiber: <
A,
E = never,
R = never
>(
evaluate: (
fiber: Fiber<unknown, unknown>
) => Effect<A, E, R>
) => Effect<A, E, R>
Provides access to the current fiber within an effect computation.
Example (Reading the current fiber)
import { Effect } from "effect"
const program = Effect.withFiber((fiber) =>
Effect.succeed(`Fiber ID: ${fiber.id}`)
)
Effect.runPromise(program).then(console.log)
// Output: Fiber ID: 1
withFiber((parent: Fiber.Fiber<unknown, unknown>(parameter) parent: {
id: number;
currentOpCount: number;
getRef: <A>(ref: Context.Reference<A>) => A;
context: Context.Context<never>;
setContext: (context: Context.Context<never>) => void;
currentScheduler: Scheduler;
currentDispatcher: SchedulerDispatcher;
currentSpan: AnySpan | undefined;
currentLogLevel: LogLevel;
minimumLogLevel: LogLevel;
currentStackFrame: StackFrame | undefined;
maxOpsBeforeYield: number;
currentPreventYield: boolean;
addObserver: (cb: (exit: Exit<A, E>) => void) => () => void;
interruptUnsafe: (fiberId?: number | undefined, annotations?: Context.Context<never> | undefined) => void;
pollUnsafe: () => Exit<A, E> | 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; <…;
}
parent) => {
const const services: Context.Context<never>const services: {
mapUnsafe: ReadonlyMap<string, any>;
mutable: boolean;
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;
}
services = parent: Fiber.Fiber<unknown, unknown>(parameter) parent: {
id: number;
currentOpCount: number;
getRef: <A>(ref: Context.Reference<A>) => A;
context: Context.Context<never>;
setContext: (context: Context.Context<never>) => void;
currentScheduler: Scheduler;
currentDispatcher: SchedulerDispatcher;
currentSpan: AnySpan | undefined;
currentLogLevel: LogLevel;
minimumLogLevel: LogLevel;
currentStackFrame: StackFrame | undefined;
maxOpsBeforeYield: number;
currentPreventYield: boolean;
addObserver: (cb: (exit: Exit<A, E>) => void) => () => void;
interruptUnsafe: (fiberId?: number | undefined, annotations?: Context.Context<never> | undefined) => void;
pollUnsafe: () => Exit<A, E> | 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; <…;
}
parent.Fiber<unknown, unknown>.context: Context.Context<never>(property) Fiber<unknown, unknown>.context: {
mapUnsafe: ReadonlyMap<string, any>;
mutable: boolean;
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
return import EffectEffect.const succeed: <A>(value: A) => Effect<A>Creates an Effect that always succeeds with a given value.
When to use
Use when an effect should complete successfully with a specific value without any errors
or external dependencies.
Example (Creating a successful effect)
import { Effect } from "effect"
// Creating an effect that represents a successful scenario
//
// ┌─── Effect<number, never, never>
// ▼
const success = Effect.succeed(42)
succeed(function function (local function) handler(nodeRequest: Http.IncomingMessage, nodeResponse: Http.ServerResponse): voidhandler(
nodeRequest: Http.IncomingMessagenodeRequest: import HttpHttp.type Http.IncomingMessage = /*unresolved*/ anyIncomingMessage,
nodeResponse: Http.ServerResponsenodeResponse: import HttpHttp.type Http.ServerResponse = /*unresolved*/ anyServerResponse
) {
const const map: Map<string, any>map = new var Map: MapConstructor
new <string, any>(iterable?: Iterable<readonly [string, any]> | null | undefined) => Map<string, any> (+3 overloads)
Map(const services: Context.Context<never>const services: {
mapUnsafe: ReadonlyMap<string, any>;
mutable: boolean;
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;
}
services.Context<never>.mapUnsafe: ReadonlyMap<string, any>mapUnsafe)
const map: Map<string, any>map.Map<string, any>.set(key: string, value: any): Map<string, any>Adds a new element with a specified key and value to the Map. If an element with the same key already exists, the element will be updated.
set(const HttpServerRequest: Context.Service<
Request.HttpServerRequest,
Request.HttpServerRequest
>
(alias) const HttpServerRequest: {
key: string;
Service: {
source: object;
url: string;
originalUrl: string;
method: HttpMethod;
cookies: ReadonlyRecord<string, string>;
multipart: Effect.Effect<Multipart.Persisted, Multipart.MultipartError, Scope.Scope | FileSystem.FileSystem | Path.Path>;
multipartStream: Stream.Stream<Multipart.Part, Multipart.MultipartError>;
upgrade: Effect.Effect<Socket.Socket, HttpServerError>;
modify: (options: { readonly url?: string; readonly headers?: Headers.Headers; readonly remoteAddress?: Option.Option<string> }) => HttpServerRequest;
headers: Headers.Headers;
remoteAddress: Option.Option<string>;
json: Effect.Effect<Schema.Json, E>;
text: Effect.Effect<string, E>;
urlParamsBody: Effect.Effect<UrlParams.UrlParams, E>;
arrayBuffer: Effect.Effect<ArrayBuffer, E>;
stream: Stream.Stream<Uint8Array, E>;
toString: () => string;
toJSON: () => unknown;
};
of: (this: void, self: Request.HttpServerRequest) => Request.HttpServerRequest;
context: (self: Request.HttpServerRequest) => Context.Context<Request.HttpServerRequest>;
use: (f: (service: Request.HttpServerRequest) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, Request.HttpServerRequest | R>;
useSync: (f: (service: Request.HttpServerRequest) => A) => Effect.Effect<A, never, Request.HttpServerRequest>;
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;
}
Server-side representation of an incoming HTTP request.
Details
It extends HttpIncomingMessage with request metadata, parsed cookies,
multipart accessors, WebSocket upgrade support, and a modify method for
creating adjusted request views.
Service tag for the active server-side HTTP request.
When to use
Use to access the request currently being handled by HTTP server routes and
middleware.
HttpServerRequest.Key<HttpServerRequest, HttpServerRequest>.key: stringkey, new constructor ServerRequestImpl(source: Http.IncomingMessage, response: Http.ServerResponse | LazyArg<Http.ServerResponse>, upgradeEffect?: Effect.Effect<Socket.Socket, HttpServerError>, url?: any, headersOverride?: Headers.Headers, remoteAddressOverride?: Option.Option<string>): ServerRequestImplServerRequestImpl(nodeRequest: Http.IncomingMessagenodeRequest, nodeResponse: Http.ServerResponsenodeResponse))
const const fiber: Fiber.Fiber<void, never>const fiber: {
id: number;
currentOpCount: number;
getRef: <A>(ref: Context.Reference<A>) => A;
context: Context.Context<never>;
setContext: (context: Context.Context<never>) => void;
currentScheduler: Scheduler;
currentDispatcher: SchedulerDispatcher;
currentSpan: AnySpan | undefined;
currentLogLevel: LogLevel;
minimumLogLevel: LogLevel;
currentStackFrame: StackFrame | undefined;
maxOpsBeforeYield: number;
currentPreventYield: boolean;
addObserver: (cb: (exit: Exit<A, E>) => void) => () => void;
interruptUnsafe: (fiberId?: number | undefined, annotations?: Context.Context<never> | undefined) => void;
pollUnsafe: () => Exit<A, E> | 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; <…;
}
fiber = import FiberFiber.const runIn: {
(scope: Scope): <A, E>(
self: Fiber<A, E>
) => Fiber<A, E>
<A, E>(self: Fiber<A, E>, scope: Scope): Fiber<
A,
E
>
}
Adds a fiber to a Scope and returns the same fiber.
When to use
Use when a manually managed fiber should be interrupted when a Scope closes.
Details
When the scope is closed, the fiber is interrupted. If the scope is already
closed, the fiber is interrupted immediately.
Gotchas
This does not wait for the fiber to complete. It only registers the
interruption finalizer and returns the same fiber.
runIn(import EffectEffect.const runForkWith: <R>(
context: Context.Context<R>
) => <A, E>(
effect: Effect<A, E, R>,
options?: RunOptions | undefined
) => Fiber<A, E>
Runs an effect in the background with the provided services.
When to use
Use when an effect still requires services, you already have a Context, and
you want a background fiber.
Example (Running with services in the background)
import { Context, Effect } from "effect"
interface Logger {
log: (message: string) => void
}
const Logger = Context.Service<Logger>("Logger")
const services = Context.make(Logger, {
log: (message) => console.log(message)
})
const program = Effect.gen(function*() {
const logger = yield* Logger
logger.log("Hello from service!")
return "done"
})
const fiber = Effect.runForkWith(services)(program)
runForkWith(import ContextContext.const makeUnsafe: <Services = never>(
mapUnsafe: ReadonlyMap<string, any>
) => Context<Services>
Creates a Context from an existing service map.
When to use
Use when constructing a low-level Context from a trusted map whose lifecycle
you control.
Gotchas
This is unsafe because later mutation of the provided map can affect the
created Context. Prefer empty, make, add, or merge for normal
Context construction.
Example (Creating a context from a map)
import { Context } from "effect"
// Create a context from a Map (unsafe)
const map = new Map([
["Logger", { log: (msg: string) => console.log(msg) }]
])
const context = Context.makeUnsafe(map)
makeUnsafe<any>(const map: Map<string, any>map))(const handled: Effect.Effect<
void,
never,
| Request.HttpServerRequest
| Exclude<R, Scope.Scope>
>
const handled: {
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;
}
handled), options: {
readonly scope: Scope.Scope
readonly middleware?:
| Middleware.HttpMiddleware.Applied<App, E, R>
| undefined
}
options.scope: Scope.Scope(property) scope: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
}
scope)
nodeResponse: Http.ServerResponsenodeResponse.on("close", () => {
if (!nodeResponse: Http.ServerResponsenodeResponse.writableEnded) {
const fiber: Fiber.Fiber<void, never>const fiber: {
id: number;
currentOpCount: number;
getRef: <A>(ref: Context.Reference<A>) => A;
context: Context.Context<never>;
setContext: (context: Context.Context<never>) => void;
currentScheduler: Scheduler;
currentDispatcher: SchedulerDispatcher;
currentSpan: AnySpan | undefined;
currentLogLevel: LogLevel;
minimumLogLevel: LogLevel;
currentStackFrame: StackFrame | undefined;
maxOpsBeforeYield: number;
currentPreventYield: boolean;
addObserver: (cb: (exit: Exit<A, E>) => void) => () => void;
interruptUnsafe: (fiberId?: number | undefined, annotations?: Context.Context<never> | undefined) => void;
pollUnsafe: () => Exit<A, E> | 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; <…;
}
fiber.Fiber<void, never>.interruptUnsafe: (fiberId?: number | undefined, annotations?: Context.Context<never> | undefined) => voidinterruptUnsafe(parent: Fiber.Fiber<unknown, unknown>(parameter) parent: {
id: number;
currentOpCount: number;
getRef: <A>(ref: Context.Reference<A>) => A;
context: Context.Context<never>;
setContext: (context: Context.Context<never>) => void;
currentScheduler: Scheduler;
currentDispatcher: SchedulerDispatcher;
currentSpan: AnySpan | undefined;
currentLogLevel: LogLevel;
minimumLogLevel: LogLevel;
currentStackFrame: StackFrame | undefined;
maxOpsBeforeYield: number;
currentPreventYield: boolean;
addObserver: (cb: (exit: Exit<A, E>) => void) => () => void;
interruptUnsafe: (fiberId?: number | undefined, annotations?: Context.Context<never> | undefined) => void;
pollUnsafe: () => Exit<A, E> | 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; <…;
}
parent.Fiber<unknown, unknown>.id: numberid, class ClientAbortclass ClientAbort {
annotation: Context.Context<Cause.StackTrace | ClientAbort>;
key: Identifier;
of: (this: void, self: true) => true;
context: (self: true) => Context.Context<ClientAbort>;
use: (f: (service: true) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, ClientAbort | R>;
useSync: (f: (service: true) => A) => Effect.Effect<A, never, ClientAbort>;
Identifier: Identifier;
Service: Shape;
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 annotation used to mark an interrupt as caused by the client aborting
the request.
Details
causeResponse uses this annotation to map a pure client abort to a 499
response instead of a server abort response.
ClientAbort.ClientAbort.annotation: Context.Context<Cause.StackTrace | ClientAbort>(property) ClientAbort.annotation: {
mapUnsafe: ReadonlyMap<string, any>;
mutable: boolean;
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;
}
annotation)
}
})
})
})
}