<S extends object>(service: S): PromiseOf<S>
<S extends object, R>(
service: S,
context: Context.Context<R>
): PromiseOf<S>Adapt a Hyperlink service handle to Promise / async — the OS edge for non-Effect consumers
(scripts, Next handlers, TanStack queryFn). Not a Spec builder: wrap the handle you already
hold from layer / client (typically via ManagedRuntime.runPromise(Tag)).
const runtime = ManagedRuntime.make(Hyperlink.layer(Counter, impl))
const handle = await runtime.runPromise(Counter)
const api = Hyperlink.promise(handle)
await api.add(1)
console.log(await api.current)
for await (const n of api.count.changes) { … }Optional context runs Effects / Streams that still need services (e.g. Local on a
local-layer handle). Default is empty context — fine for wire clients whose methods are R = never.
Failures reject the Promise / async iterator (no Result wrapper).
export function function promise<S extends object>(service: S): PromiseOf<S> (+1 overload)Adapt a Hyperlink service handle to Promise / async — the OS edge for non-Effect consumers
(scripts, Next handlers, TanStack queryFn). Not a Spec builder: wrap the handle you already
hold from
layer
/
client
(typically via ManagedRuntime.runPromise(Tag)).
const runtime = ManagedRuntime.make(Hyperlink.layer(Counter, impl))
const handle = await runtime.runPromise(Counter)
const api = Hyperlink.promise(handle)
await api.add(1)
console.log(await api.current)
for await (const n of api.count.changes) { … }
Optional context runs Effects / Streams that still need services (e.g.
Local
on a
local-layer handle). Default is empty context — fine for wire clients whose methods are R = never.
Failures reject the Promise / async iterator (no Result wrapper).
promise<function (type parameter) S in promise<S extends object>(service: S): PromiseOf<S>S extends object>(service: S extends objectservice: function (type parameter) S in promise<S extends object>(service: S): PromiseOf<S>S): type PromiseOf<S> = { readonly [K in keyof S]: S[K] extends Subscribable<infer A> ? PromiseSubscribable<A> : S[K] extends Stream.Stream<infer A, infer _E, infer _R> ? AsyncIterable<A> : S[K] extends Effect.Effect<infer A, infer _E, infer _R> ? Promise<A> : S[K] extends (...args: infer Args) => Effect.Effect<infer A, infer _E, infer _R> ? (...args: Args) => Promise<A> : S[K] extends (...args: infer Args) => Stream.Stream<infer A, infer _E, infer _R> ? (...args: Args) => AsyncIterable<A> : S[K] extends object ? PromiseOf<...> : S[K]; }A Hyperlink service handle adapted to Promise / async — what
promise
returns. Every
Effect becomes a Promise (failures reject), every Stream an AsyncIterable,
ref
fields become
PromiseSubscribable
, nested groups recurse, plain
value
s pass through.
PromiseOf<function (type parameter) S in promise<S extends object>(service: S): PromiseOf<S>S>;
export function function promise<S extends object, R>(service: S, context: Context.Context<R>): PromiseOf<S> (+1 overload)Adapt a Hyperlink service handle to Promise / async — the OS edge for non-Effect consumers
(scripts, Next handlers, TanStack queryFn). Not a Spec builder: wrap the handle you already
hold from
layer
/
client
(typically via ManagedRuntime.runPromise(Tag)).
const runtime = ManagedRuntime.make(Hyperlink.layer(Counter, impl))
const handle = await runtime.runPromise(Counter)
const api = Hyperlink.promise(handle)
await api.add(1)
console.log(await api.current)
for await (const n of api.count.changes) { … }
Optional context runs Effects / Streams that still need services (e.g.
Local
on a
local-layer handle). Default is empty context — fine for wire clients whose methods are R = never.
Failures reject the Promise / async iterator (no Result wrapper).
promise<function (type parameter) S in promise<S extends object, R>(service: S, context: Context.Context<R>): PromiseOf<S>S extends object, function (type parameter) R in promise<S extends object, R>(service: S, context: Context.Context<R>): PromiseOf<S>R>(
service: S extends objectservice: function (type parameter) S in promise<S extends object, R>(service: S, context: Context.Context<R>): PromiseOf<S>S,
context: Context.Context<R>(parameter) 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: import ContextContext.interface Context<in Services>Immutable collection of service implementations used for dependency
injection in Effect programs.
Details
The type parameter tracks the service identifiers available in the context.
At runtime, services are stored by each key's string key.
Example (Creating a context with multiple services)
import { Context } from "effect"
// Create a context with multiple services
const Logger = Context.Service<{ log: (msg: string) => void }>("Logger")
const Database = Context.Service<{ query: (sql: string) => string }>(
"Database"
)
const context = Context.make(Logger, {
log: (msg: string) => console.log(msg)
})
.pipe(Context.add(Database, { query: (sql) => `Result: ${sql}` }))
Context<function (type parameter) R in promise<S extends object, R>(service: S, context: Context.Context<R>): PromiseOf<S>R>,
): type PromiseOf<S> = { readonly [K in keyof S]: S[K] extends Subscribable<infer A> ? PromiseSubscribable<A> : S[K] extends Stream.Stream<infer A, infer _E, infer _R> ? AsyncIterable<A> : S[K] extends Effect.Effect<infer A, infer _E, infer _R> ? Promise<A> : S[K] extends (...args: infer Args) => Effect.Effect<infer A, infer _E, infer _R> ? (...args: Args) => Promise<A> : S[K] extends (...args: infer Args) => Stream.Stream<infer A, infer _E, infer _R> ? (...args: Args) => AsyncIterable<A> : S[K] extends object ? PromiseOf<...> : S[K]; }A Hyperlink service handle adapted to Promise / async — what
promise
returns. Every
Effect becomes a Promise (failures reject), every Stream an AsyncIterable,
ref
fields become
PromiseSubscribable
, nested groups recurse, plain
value
s pass through.
PromiseOf<function (type parameter) S in promise<S extends object, R>(service: S, context: Context.Context<R>): PromiseOf<S>S>;
export function function promise<S extends object>(service: S): PromiseOf<S> (+1 overload)Adapt a Hyperlink service handle to Promise / async — the OS edge for non-Effect consumers
(scripts, Next handlers, TanStack queryFn). Not a Spec builder: wrap the handle you already
hold from
layer
/
client
(typically via ManagedRuntime.runPromise(Tag)).
const runtime = ManagedRuntime.make(Hyperlink.layer(Counter, impl))
const handle = await runtime.runPromise(Counter)
const api = Hyperlink.promise(handle)
await api.add(1)
console.log(await api.current)
for await (const n of api.count.changes) { … }
Optional context runs Effects / Streams that still need services (e.g.
Local
on a
local-layer handle). Default is empty context — fine for wire clients whose methods are R = never.
Failures reject the Promise / async iterator (no Result wrapper).
promise<function (type parameter) S in promise<S extends object, R = never>(service: S, context?: Context.Context<R>): PromiseOf<S>S extends object, function (type parameter) R in promise<S extends object, R = never>(service: S, context?: Context.Context<R>): PromiseOf<S>R = never>(
service: S extends objectservice: function (type parameter) S in promise<S extends object, R = never>(service: S, context?: Context.Context<R>): PromiseOf<S>S,
context: Context.Context<R>context?: import ContextContext.interface Context<in Services>Immutable collection of service implementations used for dependency
injection in Effect programs.
Details
The type parameter tracks the service identifiers available in the context.
At runtime, services are stored by each key's string key.
Example (Creating a context with multiple services)
import { Context } from "effect"
// Create a context with multiple services
const Logger = Context.Service<{ log: (msg: string) => void }>("Logger")
const Database = Context.Service<{ query: (sql: string) => string }>(
"Database"
)
const context = Context.make(Logger, {
log: (msg: string) => console.log(msg)
})
.pipe(Context.add(Database, { query: (sql) => `Result: ${sql}` }))
Context<function (type parameter) R in promise<S extends object, R = never>(service: S, context?: Context.Context<R>): PromiseOf<S>R>,
): type PromiseOf<S> = { readonly [K in keyof S]: S[K] extends Subscribable<infer A> ? PromiseSubscribable<A> : S[K] extends Stream.Stream<infer A, infer _E, infer _R> ? AsyncIterable<A> : S[K] extends Effect.Effect<infer A, infer _E, infer _R> ? Promise<A> : S[K] extends (...args: infer Args) => Effect.Effect<infer A, infer _E, infer _R> ? (...args: Args) => Promise<A> : S[K] extends (...args: infer Args) => Stream.Stream<infer A, infer _E, infer _R> ? (...args: Args) => AsyncIterable<A> : S[K] extends object ? PromiseOf<...> : S[K]; }A Hyperlink service handle adapted to Promise / async — what
promise
returns. Every
Effect becomes a Promise (failures reject), every Stream an AsyncIterable,
ref
fields become
PromiseSubscribable
, nested groups recurse, plain
value
s pass through.
PromiseOf<function (type parameter) S in promise<S extends object, R = never>(service: S, context?: Context.Context<R>): PromiseOf<S>S> {
return adaptPromiseHandle<R = never>(service: object, context?: Context.Context<R>): Record<string, unknown>Adapt a service handle to Promise / async using context (default empty — wire clients with
R = never). Failures reject the Promise / async iterator.
adaptPromiseHandle(
service: S extends objectservice,
context: Context.Context<R>context ?? (import ContextContext.const empty: () => Context<never>Returns an empty Context.
Example (Creating an empty context)
import { Context } from "effect"
import * as assert from "node:assert"
assert.strictEqual(Context.isContext(Context.empty()), true)
empty() as import ContextContext.interface Context<in Services>Immutable collection of service implementations used for dependency
injection in Effect programs.
Details
The type parameter tracks the service identifiers available in the context.
At runtime, services are stored by each key's string key.
Example (Creating a context with multiple services)
import { Context } from "effect"
// Create a context with multiple services
const Logger = Context.Service<{ log: (msg: string) => void }>("Logger")
const Database = Context.Service<{ query: (sql: string) => string }>(
"Database"
)
const context = Context.make(Logger, {
log: (msg: string) => console.log(msg)
})
.pipe(Context.add(Database, { query: (sql) => `Result: ${sql}` }))
Context<function (type parameter) R in promise<S extends object, R = never>(service: S, context?: Context.Context<R>): PromiseOf<S>R>),
) as type PromiseOf<S> = { readonly [K in keyof S]: S[K] extends Subscribable<infer A> ? PromiseSubscribable<A> : S[K] extends Stream.Stream<infer A, infer _E, infer _R> ? AsyncIterable<A> : S[K] extends Effect.Effect<infer A, infer _E, infer _R> ? Promise<A> : S[K] extends (...args: infer Args) => Effect.Effect<infer A, infer _E, infer _R> ? (...args: Args) => Promise<A> : S[K] extends (...args: infer Args) => Stream.Stream<infer A, infer _E, infer _R> ? (...args: Args) => AsyncIterable<A> : S[K] extends object ? PromiseOf<...> : S[K]; }A Hyperlink service handle adapted to Promise / async — what
promise
returns. Every
Effect becomes a Promise (failures reject), every Stream an AsyncIterable,
ref
fields become
PromiseSubscribable
, nested groups recurse, plain
value
s pass through.
PromiseOf<function (type parameter) S in promise<S extends object, R = never>(service: S, context?: Context.Context<R>): PromiseOf<S>S>;
}