(
options:
| {
readonly capacity: "unbounded"
readonly replay?: number | undefined
}
| {
readonly capacity: number
readonly strategy?: "dropping" | "sliding" | "suspend" | undefined
readonly replay?: number | undefined
}
): <OutElem, OutErr, OutDone, Env>(
self: Channel<
Arr.NonEmptyReadonlyArray<OutDone>,
OutErr,
OutDone,
unknown,
unknown,
unknown,
Env
>
) => Effect.Effect<
PubSub.PubSub<Take.Take<OutElem, OutErr, OutDone>>,
never,
Env | Scope.Scope
>
<OutElem, OutErr, OutDone, Env>(
self: Channel<
Arr.NonEmptyReadonlyArray<OutElem>,
OutErr,
OutDone,
unknown,
unknown,
unknown,
Env
>,
options:
| {
readonly capacity: "unbounded"
readonly replay?: number | undefined
}
| {
readonly capacity: number
readonly strategy?: "dropping" | "sliding" | "suspend" | undefined
readonly replay?: number | undefined
}
): Effect.Effect<
PubSub.PubSub<Take.Take<OutElem, OutErr, OutDone>>,
never,
Env | Scope.Scope
>Converts a channel to a scoped PubSub of Take values.
Details
Emitted non-empty arrays are published as output Take values. When the
channel ends, its final Exit is published so subscribers can observe
completion or failure.
export const const toPubSubTake: {
(
options:
| {
readonly capacity: "unbounded"
readonly replay?: number | undefined
}
| {
readonly capacity: number
readonly strategy?:
| "dropping"
| "sliding"
| "suspend"
| undefined
readonly replay?: number | undefined
}
): <OutElem, OutErr, OutDone, Env>(
self: Channel<
Arr.NonEmptyReadonlyArray<OutDone>,
OutErr,
OutDone,
unknown,
unknown,
unknown,
Env
>
) => Effect.Effect<
PubSub.PubSub<
Take.Take<OutElem, OutErr, OutDone>
>,
never,
Env | Scope.Scope
>
<OutElem, OutErr, OutDone, Env>(
self: Channel<
Arr.NonEmptyReadonlyArray<OutElem>,
OutErr,
OutDone,
unknown,
unknown,
unknown,
Env
>,
options:
| {
readonly capacity: "unbounded"
readonly replay?: number | undefined
}
| {
readonly capacity: number
readonly strategy?:
| "dropping"
| "sliding"
| "suspend"
| undefined
readonly replay?: number | undefined
}
): Effect.Effect<
PubSub.PubSub<
Take.Take<OutElem, OutErr, OutDone>
>,
never,
Env | Scope.Scope
>
}
Converts a channel to a scoped PubSub of Take values.
Details
Emitted non-empty arrays are published as output Take values. When the
channel ends, its final Exit is published so subscribers can observe
completion or failure.
toPubSubTake: {
(
options: | {
readonly capacity: "unbounded"
readonly replay?: number | undefined
}
| {
readonly capacity: number
readonly strategy?:
| "dropping"
| "sliding"
| "suspend"
| undefined
readonly replay?: number | undefined
}
options: {
readonly capacity: "unbounded"capacity: "unbounded"
readonly replay?: number | undefinedreplay?: number | undefined
} | {
readonly capacity: numbercapacity: number
readonly strategy?: | "sliding"
| "dropping"
| "suspend"
| undefined
strategy?: "dropping" | "sliding" | "suspend" | undefined
readonly replay?: number | undefinedreplay?: number | undefined
}
): <function (type parameter) OutElem in <OutElem, OutErr, OutDone, Env>(self: Channel<Arr.NonEmptyReadonlyArray<OutDone>, OutErr, OutDone, unknown, unknown, unknown, Env>): Effect.Effect<PubSub.PubSub<Take.Take<OutElem, OutErr, OutDone>>, never, Env | Scope.Scope>OutElem, function (type parameter) OutErr in <OutElem, OutErr, OutDone, Env>(self: Channel<Arr.NonEmptyReadonlyArray<OutDone>, OutErr, OutDone, unknown, unknown, unknown, Env>): Effect.Effect<PubSub.PubSub<Take.Take<OutElem, OutErr, OutDone>>, never, Env | Scope.Scope>OutErr, function (type parameter) OutDone in <OutElem, OutErr, OutDone, Env>(self: Channel<Arr.NonEmptyReadonlyArray<OutDone>, OutErr, OutDone, unknown, unknown, unknown, Env>): Effect.Effect<PubSub.PubSub<Take.Take<OutElem, OutErr, OutDone>>, never, Env | Scope.Scope>OutDone, function (type parameter) Env in <OutElem, OutErr, OutDone, Env>(self: Channel<Arr.NonEmptyReadonlyArray<OutDone>, OutErr, OutDone, unknown, unknown, unknown, Env>): Effect.Effect<PubSub.PubSub<Take.Take<OutElem, OutErr, OutDone>>, never, Env | Scope.Scope>Env>(
self: Channel<
Arr.NonEmptyReadonlyArray<OutDone>,
OutErr,
OutDone,
unknown,
unknown,
unknown,
Env
>
(parameter) self: {
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; <…;
}
self: interface Channel<out OutElem, out OutErr = never, out OutDone = void, in InElem = unknown, in InErr = unknown, in InDone = unknown, out Env = never>A Channel is a nexus of I/O operations, which supports both reading and
writing. A channel may read values of type InElem and write values of type
OutElem. When the channel finishes, it yields a value of type OutDone. A
channel may fail with a value of type OutErr.
Details
Channels are the foundation of Streams: both streams and sinks are built on
channels. Most users shouldn't have to use channels directly, as streams and
sinks are much more convenient and cover all common use cases. However, when
adding new stream and sink operators, or doing something highly specialized,
it may be useful to use channels directly.
Channels compose in a variety of ways:
- Piping: One channel can be piped to another channel, assuming the
input type of the second is the same as the output type of the first.
- Sequencing: The terminal value of one channel can be used to create
another channel, and both the first channel and the function that makes
the second channel can be composed into a channel.
- Concatenating: The output of one channel can be used to create other
channels, which are all concatenated together. The first channel and the
function that makes the other channels can be composed into a channel.
Example (Typing channels)
import type { Channel } from "effect"
// A channel that outputs numbers and requires no environment
type NumberChannel = Channel.Channel<number>
// A channel that outputs strings, can fail with Error, completes with boolean
type StringChannel = Channel.Channel<string, Error, boolean>
// A channel with all type parameters specified
type FullChannel = Channel.Channel<
string, // OutElem - output elements
Error, // OutErr - output errors
number, // OutDone - completion value
number, // InElem - input elements
string, // InErr - input errors
boolean, // InDone - input completion
{ db: string } // Env - required environment
>
Channel<import ArrArr.type Arr.NonEmptyReadonlyArray = /*unresolved*/ anyNonEmptyReadonlyArray<function (type parameter) OutDone in <OutElem, OutErr, OutDone, Env>(self: Channel<Arr.NonEmptyReadonlyArray<OutDone>, OutErr, OutDone, unknown, unknown, unknown, Env>): Effect.Effect<PubSub.PubSub<Take.Take<OutElem, OutErr, OutDone>>, never, Env | Scope.Scope>OutDone>, function (type parameter) OutErr in <OutElem, OutErr, OutDone, Env>(self: Channel<Arr.NonEmptyReadonlyArray<OutDone>, OutErr, OutDone, unknown, unknown, unknown, Env>): Effect.Effect<PubSub.PubSub<Take.Take<OutElem, OutErr, OutDone>>, never, Env | Scope.Scope>OutErr, function (type parameter) OutDone in <OutElem, OutErr, OutDone, Env>(self: Channel<Arr.NonEmptyReadonlyArray<OutDone>, OutErr, OutDone, unknown, unknown, unknown, Env>): Effect.Effect<PubSub.PubSub<Take.Take<OutElem, OutErr, OutDone>>, never, Env | Scope.Scope>OutDone, unknown, unknown, unknown, function (type parameter) Env in <OutElem, OutErr, OutDone, Env>(self: Channel<Arr.NonEmptyReadonlyArray<OutDone>, OutErr, OutDone, unknown, unknown, unknown, Env>): Effect.Effect<PubSub.PubSub<Take.Take<OutElem, OutErr, OutDone>>, never, Env | Scope.Scope>Env>
) => 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<
import PubSubPubSub.interface PubSub<in out A>A PubSub<A> is an asynchronous message hub into which publishers can publish
messages of type A and subscribers can subscribe to take messages of type
A.
Example (Publishing and subscribing to messages)
import { Effect, PubSub } from "effect"
const program = Effect.gen(function*() {
// Create a bounded PubSub with capacity 10
const pubsub = yield* PubSub.bounded<string>(10)
// Subscribe and consume messages
yield* Effect.scoped(Effect.gen(function*() {
const subscription = yield* PubSub.subscribe(pubsub)
// Publish messages
yield* PubSub.publish(pubsub, "Hello")
yield* PubSub.publish(pubsub, "World")
const message1 = yield* PubSub.take(subscription)
const message2 = yield* PubSub.take(subscription)
console.log(message1, message2) // "Hello", "World"
}))
})
Companion namespace containing the low-level building blocks used by
PubSub, including atomic implementations, backing subscriptions, replay
windows, and delivery strategies.
PubSub<import TakeTake.type Take<A, E = never, Done = void> = anyRepresents one pull result: either a non-empty batch of values, a failure
Exit, or a successful Exit that signals completion with a Done value.
When to use
Use to store, transfer, or interpret pull results later while preserving
emitted values, failures, and normal completion.
Take<function (type parameter) OutElem in <OutElem, OutErr, OutDone, Env>(self: Channel<Arr.NonEmptyReadonlyArray<OutDone>, OutErr, OutDone, unknown, unknown, unknown, Env>): Effect.Effect<PubSub.PubSub<Take.Take<OutElem, OutErr, OutDone>>, never, Env | Scope.Scope>OutElem, function (type parameter) OutErr in <OutElem, OutErr, OutDone, Env>(self: Channel<Arr.NonEmptyReadonlyArray<OutDone>, OutErr, OutDone, unknown, unknown, unknown, Env>): Effect.Effect<PubSub.PubSub<Take.Take<OutElem, OutErr, OutDone>>, never, Env | Scope.Scope>OutErr, function (type parameter) OutDone in <OutElem, OutErr, OutDone, Env>(self: Channel<Arr.NonEmptyReadonlyArray<OutDone>, OutErr, OutDone, unknown, unknown, unknown, Env>): Effect.Effect<PubSub.PubSub<Take.Take<OutElem, OutErr, OutDone>>, never, Env | Scope.Scope>OutDone>>,
never,
function (type parameter) Env in <OutElem, OutErr, OutDone, Env>(self: Channel<Arr.NonEmptyReadonlyArray<OutDone>, OutErr, OutDone, unknown, unknown, unknown, Env>): Effect.Effect<PubSub.PubSub<Take.Take<OutElem, OutErr, OutDone>>, never, Env | Scope.Scope>Env | import ScopeScope.Scope
>
<function (type parameter) OutElem in <OutElem, OutErr, OutDone, Env>(self: Channel<Arr.NonEmptyReadonlyArray<OutElem>, OutErr, OutDone, unknown, unknown, unknown, Env>, options: {
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly strategy?: "dropping" | "sliding" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Effect.Effect<PubSub.PubSub<Take.Take<OutElem, OutErr, OutDone>>, never, Env | Scope.Scope>
OutElem, function (type parameter) OutErr in <OutElem, OutErr, OutDone, Env>(self: Channel<Arr.NonEmptyReadonlyArray<OutElem>, OutErr, OutDone, unknown, unknown, unknown, Env>, options: {
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly strategy?: "dropping" | "sliding" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Effect.Effect<PubSub.PubSub<Take.Take<OutElem, OutErr, OutDone>>, never, Env | Scope.Scope>
OutErr, function (type parameter) OutDone in <OutElem, OutErr, OutDone, Env>(self: Channel<Arr.NonEmptyReadonlyArray<OutElem>, OutErr, OutDone, unknown, unknown, unknown, Env>, options: {
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly strategy?: "dropping" | "sliding" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Effect.Effect<PubSub.PubSub<Take.Take<OutElem, OutErr, OutDone>>, never, Env | Scope.Scope>
OutDone, function (type parameter) Env in <OutElem, OutErr, OutDone, Env>(self: Channel<Arr.NonEmptyReadonlyArray<OutElem>, OutErr, OutDone, unknown, unknown, unknown, Env>, options: {
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly strategy?: "dropping" | "sliding" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Effect.Effect<PubSub.PubSub<Take.Take<OutElem, OutErr, OutDone>>, never, Env | Scope.Scope>
Env>(
self: Channel<
Arr.NonEmptyReadonlyArray<OutElem>,
OutErr,
OutDone,
unknown,
unknown,
unknown,
Env
>
(parameter) self: {
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; <…;
}
self: interface Channel<out OutElem, out OutErr = never, out OutDone = void, in InElem = unknown, in InErr = unknown, in InDone = unknown, out Env = never>A Channel is a nexus of I/O operations, which supports both reading and
writing. A channel may read values of type InElem and write values of type
OutElem. When the channel finishes, it yields a value of type OutDone. A
channel may fail with a value of type OutErr.
Details
Channels are the foundation of Streams: both streams and sinks are built on
channels. Most users shouldn't have to use channels directly, as streams and
sinks are much more convenient and cover all common use cases. However, when
adding new stream and sink operators, or doing something highly specialized,
it may be useful to use channels directly.
Channels compose in a variety of ways:
- Piping: One channel can be piped to another channel, assuming the
input type of the second is the same as the output type of the first.
- Sequencing: The terminal value of one channel can be used to create
another channel, and both the first channel and the function that makes
the second channel can be composed into a channel.
- Concatenating: The output of one channel can be used to create other
channels, which are all concatenated together. The first channel and the
function that makes the other channels can be composed into a channel.
Example (Typing channels)
import type { Channel } from "effect"
// A channel that outputs numbers and requires no environment
type NumberChannel = Channel.Channel<number>
// A channel that outputs strings, can fail with Error, completes with boolean
type StringChannel = Channel.Channel<string, Error, boolean>
// A channel with all type parameters specified
type FullChannel = Channel.Channel<
string, // OutElem - output elements
Error, // OutErr - output errors
number, // OutDone - completion value
number, // InElem - input elements
string, // InErr - input errors
boolean, // InDone - input completion
{ db: string } // Env - required environment
>
Channel<import ArrArr.type Arr.NonEmptyReadonlyArray = /*unresolved*/ anyNonEmptyReadonlyArray<function (type parameter) OutElem in <OutElem, OutErr, OutDone, Env>(self: Channel<Arr.NonEmptyReadonlyArray<OutElem>, OutErr, OutDone, unknown, unknown, unknown, Env>, options: {
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly strategy?: "dropping" | "sliding" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Effect.Effect<PubSub.PubSub<Take.Take<OutElem, OutErr, OutDone>>, never, Env | Scope.Scope>
OutElem>, function (type parameter) OutErr in <OutElem, OutErr, OutDone, Env>(self: Channel<Arr.NonEmptyReadonlyArray<OutElem>, OutErr, OutDone, unknown, unknown, unknown, Env>, options: {
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly strategy?: "dropping" | "sliding" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Effect.Effect<PubSub.PubSub<Take.Take<OutElem, OutErr, OutDone>>, never, Env | Scope.Scope>
OutErr, function (type parameter) OutDone in <OutElem, OutErr, OutDone, Env>(self: Channel<Arr.NonEmptyReadonlyArray<OutElem>, OutErr, OutDone, unknown, unknown, unknown, Env>, options: {
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly strategy?: "dropping" | "sliding" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Effect.Effect<PubSub.PubSub<Take.Take<OutElem, OutErr, OutDone>>, never, Env | Scope.Scope>
OutDone, unknown, unknown, unknown, function (type parameter) Env in <OutElem, OutErr, OutDone, Env>(self: Channel<Arr.NonEmptyReadonlyArray<OutElem>, OutErr, OutDone, unknown, unknown, unknown, Env>, options: {
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly strategy?: "dropping" | "sliding" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Effect.Effect<PubSub.PubSub<Take.Take<OutElem, OutErr, OutDone>>, never, Env | Scope.Scope>
Env>,
options: | {
readonly capacity: "unbounded"
readonly replay?: number | undefined
}
| {
readonly capacity: number
readonly strategy?:
| "dropping"
| "sliding"
| "suspend"
| undefined
readonly replay?: number | undefined
}
options: {
readonly capacity: "unbounded"capacity: "unbounded"
readonly replay?: number | undefinedreplay?: number | undefined
} | {
readonly capacity: numbercapacity: number
readonly strategy?: | "sliding"
| "dropping"
| "suspend"
| undefined
strategy?: "dropping" | "sliding" | "suspend" | undefined
readonly replay?: number | undefinedreplay?: number | 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<
import PubSubPubSub.interface PubSub<in out A>A PubSub<A> is an asynchronous message hub into which publishers can publish
messages of type A and subscribers can subscribe to take messages of type
A.
Example (Publishing and subscribing to messages)
import { Effect, PubSub } from "effect"
const program = Effect.gen(function*() {
// Create a bounded PubSub with capacity 10
const pubsub = yield* PubSub.bounded<string>(10)
// Subscribe and consume messages
yield* Effect.scoped(Effect.gen(function*() {
const subscription = yield* PubSub.subscribe(pubsub)
// Publish messages
yield* PubSub.publish(pubsub, "Hello")
yield* PubSub.publish(pubsub, "World")
const message1 = yield* PubSub.take(subscription)
const message2 = yield* PubSub.take(subscription)
console.log(message1, message2) // "Hello", "World"
}))
})
Companion namespace containing the low-level building blocks used by
PubSub, including atomic implementations, backing subscriptions, replay
windows, and delivery strategies.
PubSub<import TakeTake.type Take<A, E = never, Done = void> = anyRepresents one pull result: either a non-empty batch of values, a failure
Exit, or a successful Exit that signals completion with a Done value.
When to use
Use to store, transfer, or interpret pull results later while preserving
emitted values, failures, and normal completion.
Take<function (type parameter) OutElem in <OutElem, OutErr, OutDone, Env>(self: Channel<Arr.NonEmptyReadonlyArray<OutElem>, OutErr, OutDone, unknown, unknown, unknown, Env>, options: {
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly strategy?: "dropping" | "sliding" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Effect.Effect<PubSub.PubSub<Take.Take<OutElem, OutErr, OutDone>>, never, Env | Scope.Scope>
OutElem, function (type parameter) OutErr in <OutElem, OutErr, OutDone, Env>(self: Channel<Arr.NonEmptyReadonlyArray<OutElem>, OutErr, OutDone, unknown, unknown, unknown, Env>, options: {
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly strategy?: "dropping" | "sliding" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Effect.Effect<PubSub.PubSub<Take.Take<OutElem, OutErr, OutDone>>, never, Env | Scope.Scope>
OutErr, function (type parameter) OutDone in <OutElem, OutErr, OutDone, Env>(self: Channel<Arr.NonEmptyReadonlyArray<OutElem>, OutErr, OutDone, unknown, unknown, unknown, Env>, options: {
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly strategy?: "dropping" | "sliding" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Effect.Effect<PubSub.PubSub<Take.Take<OutElem, OutErr, OutDone>>, never, Env | Scope.Scope>
OutDone>>,
never,
function (type parameter) Env in <OutElem, OutErr, OutDone, Env>(self: Channel<Arr.NonEmptyReadonlyArray<OutElem>, OutErr, OutDone, unknown, unknown, unknown, Env>, options: {
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly strategy?: "dropping" | "sliding" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Effect.Effect<PubSub.PubSub<Take.Take<OutElem, OutErr, OutDone>>, never, Env | Scope.Scope>
Env | import ScopeScope.Scope
>
} = dual<(...args: Array<any>) => any, <OutElem, OutErr, OutDone, Env>(self: Channel<Arr.NonEmptyReadonlyArray<OutElem>, OutErr, OutDone, unknown, unknown, unknown, Env>, options: {
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly strategy?: "dropping" | "sliding" | "suspend" | undefined;
readonly replay?: number | undefined;
}) => Effect.Effect<PubSub.PubSub<any>, never, Scope.Scope | Env>>(arity: 2, body: <OutElem, OutErr, OutDone, Env>(self: Channel<Arr.NonEmptyReadonlyArray<OutElem>, OutErr, OutDone, unknown, unknown, unknown, Env>, options: {
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly strategy?: "dropping" | "sliding" | "suspend" | undefined;
readonly replay?: number | undefined;
}) => Effect.Effect<PubSub.PubSub<any>, never, Scope.Scope | Env>): ((...args: Array<any>) => any) & (<OutElem, OutErr, OutDone, Env>(self: Channel<Arr.NonEmptyReadonlyArray<OutElem>, OutErr, OutDone, unknown, unknown, unknown, Env>, options: {
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly strategy?: "dropping" | "sliding" | "suspend" | undefined;
readonly replay?: number | undefined;
}) => Effect.Effect<PubSub.PubSub<any>, never, Scope.Scope | Env>) (+1 overload)
Creates a function that can be called in data-first style or data-last
(pipe-friendly) style.
When to use
Use to expose one implementation through both direct and pipe-friendly
call styles.
Details
Pass either the arity of the uncurried function or a predicate that decides
whether the current call is data-first. Arity is the common case. Use a
predicate when optional arguments make arity ambiguous.
Example (Selecting data-first or data-last style by arity)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(2, (self, that) => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Defining overloads with call signatures)
import { Function, pipe } from "effect"
const sum: {
(that: number): (self: number) => number
(self: number, that: number): number
} = Function.dual(2, (self: number, that: number): number => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Selecting data-first or data-last style with a predicate)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(
(args) => args.length === 2,
(self, that) => self + that
)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
dual(
2,
import EffectEffect.const fnUntraced: <Effect.Effect<PubSub.PubSub<any>, never, Scope.Scope> | Effect.Effect<Fiber.Fiber<OutDone, OutErr>, never, Scope.Scope | Env>, PubSub.PubSub<any>, [self: Channel<Arr.NonEmptyReadonlyArray<OutElem>, OutErr, OutDone, unknown, unknown, unknown, Env>, options: {
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly strategy?: "dropping" | "sliding" | "suspend" | undefined;
readonly replay?: number | undefined;
}]>(body: (this: Types.unassigned, self: Channel<...>, options: {
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly strategy?: "dropping" | "sliding" | "suspend" | undefined;
readonly replay?: number | undefined;
}) => Generator<...>) => <OutElem, OutErr, OutDone, Env>(self: Channel<...>, options: {
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly strategy?: "dropping" | "sliding" | "suspend" | undefined;
readonly replay?: number | undefined;
}) => Effect.Effect<...> (+41 overloads)
fnUntraced(function*<function (type parameter) OutElem in <OutElem, OutErr, OutDone, Env>(self: Channel<Arr.NonEmptyReadonlyArray<OutElem>, OutErr, OutDone, unknown, unknown, unknown, Env>, options: {
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly strategy?: "dropping" | "sliding" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Generator<...>
OutElem, function (type parameter) OutErr in <OutElem, OutErr, OutDone, Env>(self: Channel<Arr.NonEmptyReadonlyArray<OutElem>, OutErr, OutDone, unknown, unknown, unknown, Env>, options: {
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly strategy?: "dropping" | "sliding" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Generator<...>
OutErr, function (type parameter) OutDone in <OutElem, OutErr, OutDone, Env>(self: Channel<Arr.NonEmptyReadonlyArray<OutElem>, OutErr, OutDone, unknown, unknown, unknown, Env>, options: {
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly strategy?: "dropping" | "sliding" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Generator<...>
OutDone, function (type parameter) Env in <OutElem, OutErr, OutDone, Env>(self: Channel<Arr.NonEmptyReadonlyArray<OutElem>, OutErr, OutDone, unknown, unknown, unknown, Env>, options: {
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly strategy?: "dropping" | "sliding" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Generator<...>
Env>(
self: Channel<
Arr.NonEmptyReadonlyArray<OutElem>,
OutErr,
OutDone,
unknown,
unknown,
unknown,
Env
>
(parameter) self: {
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; <…;
}
self: interface Channel<out OutElem, out OutErr = never, out OutDone = void, in InElem = unknown, in InErr = unknown, in InDone = unknown, out Env = never>A Channel is a nexus of I/O operations, which supports both reading and
writing. A channel may read values of type InElem and write values of type
OutElem. When the channel finishes, it yields a value of type OutDone. A
channel may fail with a value of type OutErr.
Details
Channels are the foundation of Streams: both streams and sinks are built on
channels. Most users shouldn't have to use channels directly, as streams and
sinks are much more convenient and cover all common use cases. However, when
adding new stream and sink operators, or doing something highly specialized,
it may be useful to use channels directly.
Channels compose in a variety of ways:
- Piping: One channel can be piped to another channel, assuming the
input type of the second is the same as the output type of the first.
- Sequencing: The terminal value of one channel can be used to create
another channel, and both the first channel and the function that makes
the second channel can be composed into a channel.
- Concatenating: The output of one channel can be used to create other
channels, which are all concatenated together. The first channel and the
function that makes the other channels can be composed into a channel.
Example (Typing channels)
import type { Channel } from "effect"
// A channel that outputs numbers and requires no environment
type NumberChannel = Channel.Channel<number>
// A channel that outputs strings, can fail with Error, completes with boolean
type StringChannel = Channel.Channel<string, Error, boolean>
// A channel with all type parameters specified
type FullChannel = Channel.Channel<
string, // OutElem - output elements
Error, // OutErr - output errors
number, // OutDone - completion value
number, // InElem - input elements
string, // InErr - input errors
boolean, // InDone - input completion
{ db: string } // Env - required environment
>
Channel<import ArrArr.type Arr.NonEmptyReadonlyArray = /*unresolved*/ anyNonEmptyReadonlyArray<function (type parameter) OutElem in <OutElem, OutErr, OutDone, Env>(self: Channel<Arr.NonEmptyReadonlyArray<OutElem>, OutErr, OutDone, unknown, unknown, unknown, Env>, options: {
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly strategy?: "dropping" | "sliding" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Generator<...>
OutElem>, function (type parameter) OutErr in <OutElem, OutErr, OutDone, Env>(self: Channel<Arr.NonEmptyReadonlyArray<OutElem>, OutErr, OutDone, unknown, unknown, unknown, Env>, options: {
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly strategy?: "dropping" | "sliding" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Generator<...>
OutErr, function (type parameter) OutDone in <OutElem, OutErr, OutDone, Env>(self: Channel<Arr.NonEmptyReadonlyArray<OutElem>, OutErr, OutDone, unknown, unknown, unknown, Env>, options: {
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly strategy?: "dropping" | "sliding" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Generator<...>
OutDone, unknown, unknown, unknown, function (type parameter) Env in <OutElem, OutErr, OutDone, Env>(self: Channel<Arr.NonEmptyReadonlyArray<OutElem>, OutErr, OutDone, unknown, unknown, unknown, Env>, options: {
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly strategy?: "dropping" | "sliding" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Generator<...>
Env>,
options: | {
readonly capacity: "unbounded"
readonly replay?: number | undefined
}
| {
readonly capacity: number
readonly strategy?:
| "dropping"
| "sliding"
| "suspend"
| undefined
readonly replay?: number | undefined
}
options: {
readonly capacity: "unbounded"capacity: "unbounded"
readonly replay?: number | undefinedreplay?: number | undefined
} | {
readonly capacity: numbercapacity: number
readonly strategy?: | "sliding"
| "dropping"
| "suspend"
| undefined
strategy?: "dropping" | "sliding" | "suspend" | undefined
readonly replay?: number | undefinedreplay?: number | undefined
}
) {
const const pubsub: PubSub.PubSub<
Take.Take<OutElem, OutErr, OutDone>
>
const pubsub: {
pubsub: PubSub.Atomic<A>;
subscribers: PubSub.Subscribers<A>;
scope: Scope.Closeable;
shutdownHook: Latch.Latch;
shutdownFlag: MutableRef.MutableRef<boolean>;
strategy: PubSub.Strategy<A>;
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; <…;
}
pubsub = yield* const makePubSub: <any>(
options:
| {
readonly capacity: "unbounded"
readonly replay?: number | undefined
}
| {
readonly capacity: number
readonly strategy?:
| "dropping"
| "sliding"
| "suspend"
| undefined
readonly replay?: number | undefined
}
) => Effect.Effect<
PubSub.PubSub<any>,
never,
Scope.Scope
>
makePubSub<import TakeTake.type Take<A, E = never, Done = void> = anyRepresents one pull result: either a non-empty batch of values, a failure
Exit, or a successful Exit that signals completion with a Done value.
When to use
Use to store, transfer, or interpret pull results later while preserving
emitted values, failures, and normal completion.
Take<function (type parameter) OutElem in <OutElem, OutErr, OutDone, Env>(self: Channel<Arr.NonEmptyReadonlyArray<OutElem>, OutErr, OutDone, unknown, unknown, unknown, Env>, options: {
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly strategy?: "dropping" | "sliding" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Generator<...>
OutElem, function (type parameter) OutErr in <OutElem, OutErr, OutDone, Env>(self: Channel<Arr.NonEmptyReadonlyArray<OutElem>, OutErr, OutDone, unknown, unknown, unknown, Env>, options: {
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly strategy?: "dropping" | "sliding" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Generator<...>
OutErr, function (type parameter) OutDone in <OutElem, OutErr, OutDone, Env>(self: Channel<Arr.NonEmptyReadonlyArray<OutElem>, OutErr, OutDone, unknown, unknown, unknown, Env>, options: {
readonly capacity: "unbounded";
readonly replay?: number | undefined;
} | {
readonly capacity: number;
readonly strategy?: "dropping" | "sliding" | "suspend" | undefined;
readonly replay?: number | undefined;
}): Generator<...>
OutDone>>(options: | {
readonly capacity: "unbounded"
readonly replay?: number | undefined
}
| {
readonly capacity: number
readonly strategy?:
| "dropping"
| "sliding"
| "suspend"
| undefined
readonly replay?: number | undefined
}
options)
yield* const runForEach: {
<OutElem, EX, RX>(
f: (o: OutElem) => Effect.Effect<void, EX, RX>
): <OutErr, OutDone, Env>(
self: Channel<
OutElem,
OutErr,
OutDone,
unknown,
unknown,
unknown,
Env
>
) => Effect.Effect<
OutDone,
OutErr | EX,
Env | RX
>
<OutElem, OutErr, OutDone, Env, EX, RX>(
self: Channel<
OutElem,
OutErr,
OutDone,
unknown,
unknown,
unknown,
Env
>,
f: (o: OutElem) => Effect.Effect<void, EX, RX>
): Effect.Effect<OutDone, OutErr | EX, Env | RX>
}
runForEach(self: Channel<
Arr.NonEmptyReadonlyArray<OutElem>,
OutErr,
OutDone,
unknown,
unknown,
unknown,
Env
>
(parameter) self: {
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; <…;
}
self, (value: Arr.NonEmptyReadonlyArray<OutElem>(parameter) value: {
0: OutElem;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<OutElem>>): Array<OutElem>; (...items: Array<OutElem | ConcatArray<OutElem>>): Array<OutElem> };
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<OutElem>;
indexOf: (searchElement: OutElem, fromIndex?: number) => number;
lastIndexOf: (searchElement: OutElem, fromIndex?: number) => number;
every: { (predicate: (value: OutElem, index: number, array: ReadonlyArray<OutElem>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: OutElem, index: number, array: ReadonlyArray<OutElem>) => unknown, thisArg?: any): boolea…;
some: (predicate: (value: OutElem, index: number, array: ReadonlyArray<OutElem>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: OutElem, index: number, array: ReadonlyArray<OutElem>) => void, thisArg?: any) => void;
map: (callbackfn: (value: OutElem, index: number, array: ReadonlyArray<OutElem>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: OutElem, index: number, array: ReadonlyArray<OutElem>) => value is S, thisArg?: any): Array<S>; (predicate: (value: OutElem, index: number, array: ReadonlyArray<OutElem>) => unknown, thisArg?: any): Array<OutElem> };
reduce: { (callbackfn: (previousValue: OutElem, currentValue: OutElem, currentIndex: number, array: ReadonlyArray<OutElem>) => OutElem): OutElem; (callbackfn: (previousValue: OutElem, currentValue: OutElem, currentIndex: number, array: ReadonlyArr…;
reduceRight: { (callbackfn: (previousValue: OutElem, currentValue: OutElem, currentIndex: number, array: ReadonlyArray<OutElem>) => OutElem): OutElem; (callbackfn: (previousValue: OutElem, currentValue: OutElem, currentIndex: number, array: ReadonlyArr…;
find: { (predicate: (value: OutElem, index: number, obj: ReadonlyArray<OutElem>) => value is S, thisArg?: any): S | undefined; (predicate: (value: OutElem, index: number, obj: ReadonlyArray<OutElem>) => unknown, thisArg?: any): OutElem | undefin…;
findIndex: (predicate: (value: OutElem, index: number, obj: ReadonlyArray<OutElem>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, OutElem]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<OutElem>;
includes: (searchElement: OutElem, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: OutElem, index: number, array: Array<OutElem>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => OutElem | undefined;
findLast: { (predicate: (value: OutElem, index: number, array: ReadonlyArray<OutElem>) => value is S, thisArg?: any): S | undefined; (predicate: (value: OutElem, index: number, array: ReadonlyArray<OutElem>) => unknown, thisArg?: any): OutElem | und…;
findLastIndex: (predicate: (value: OutElem, index: number, array: ReadonlyArray<OutElem>) => unknown, thisArg?: any) => number;
toReversed: () => Array<OutElem>;
toSorted: (compareFn?: ((a: OutElem, b: OutElem) => number) | undefined) => Array<OutElem>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<OutElem>): Array<OutElem>; (start: number, deleteCount?: number): Array<OutElem> };
with: (index: number, value: OutElem) => Array<OutElem>;
}
value) => import PubSubPubSub.const publish: {
<A>(value: A): (
self: PubSub<A>
) => Effect.Effect<boolean>
<A>(
self: PubSub<A>,
value: A
): Effect.Effect<boolean>
}
publish(const pubsub: PubSub.PubSub<
Take.Take<OutElem, OutErr, OutDone>
>
const pubsub: {
pubsub: PubSub.Atomic<A>;
subscribers: PubSub.Subscribers<A>;
scope: Scope.Closeable;
shutdownHook: Latch.Latch;
shutdownFlag: MutableRef.MutableRef<boolean>;
strategy: PubSub.Strategy<A>;
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; <…;
}
pubsub, value: Arr.NonEmptyReadonlyArray<OutElem>(parameter) value: {
0: OutElem;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<OutElem>>): Array<OutElem>; (...items: Array<OutElem | ConcatArray<OutElem>>): Array<OutElem> };
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<OutElem>;
indexOf: (searchElement: OutElem, fromIndex?: number) => number;
lastIndexOf: (searchElement: OutElem, fromIndex?: number) => number;
every: { (predicate: (value: OutElem, index: number, array: ReadonlyArray<OutElem>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: OutElem, index: number, array: ReadonlyArray<OutElem>) => unknown, thisArg?: any): boolea…;
some: (predicate: (value: OutElem, index: number, array: ReadonlyArray<OutElem>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: OutElem, index: number, array: ReadonlyArray<OutElem>) => void, thisArg?: any) => void;
map: (callbackfn: (value: OutElem, index: number, array: ReadonlyArray<OutElem>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: OutElem, index: number, array: ReadonlyArray<OutElem>) => value is S, thisArg?: any): Array<S>; (predicate: (value: OutElem, index: number, array: ReadonlyArray<OutElem>) => unknown, thisArg?: any): Array<OutElem> };
reduce: { (callbackfn: (previousValue: OutElem, currentValue: OutElem, currentIndex: number, array: ReadonlyArray<OutElem>) => OutElem): OutElem; (callbackfn: (previousValue: OutElem, currentValue: OutElem, currentIndex: number, array: ReadonlyArr…;
reduceRight: { (callbackfn: (previousValue: OutElem, currentValue: OutElem, currentIndex: number, array: ReadonlyArray<OutElem>) => OutElem): OutElem; (callbackfn: (previousValue: OutElem, currentValue: OutElem, currentIndex: number, array: ReadonlyArr…;
find: { (predicate: (value: OutElem, index: number, obj: ReadonlyArray<OutElem>) => value is S, thisArg?: any): S | undefined; (predicate: (value: OutElem, index: number, obj: ReadonlyArray<OutElem>) => unknown, thisArg?: any): OutElem | undefin…;
findIndex: (predicate: (value: OutElem, index: number, obj: ReadonlyArray<OutElem>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, OutElem]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<OutElem>;
includes: (searchElement: OutElem, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: OutElem, index: number, array: Array<OutElem>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => OutElem | undefined;
findLast: { (predicate: (value: OutElem, index: number, array: ReadonlyArray<OutElem>) => value is S, thisArg?: any): S | undefined; (predicate: (value: OutElem, index: number, array: ReadonlyArray<OutElem>) => unknown, thisArg?: any): OutElem | und…;
findLastIndex: (predicate: (value: OutElem, index: number, array: ReadonlyArray<OutElem>) => unknown, thisArg?: any) => number;
toReversed: () => Array<OutElem>;
toSorted: (compareFn?: ((a: OutElem, b: OutElem) => number) | undefined) => Array<OutElem>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<OutElem>): Array<OutElem>; (start: number, deleteCount?: number): Array<OutElem> };
with: (index: number, value: OutElem) => Array<OutElem>;
}
value)).Pipeable.pipe<Effect.Effect<OutDone, OutErr, Env>, Effect.Effect<OutDone, OutErr, Env>, Effect.Effect<Fiber.Fiber<OutDone, OutErr>, never, Scope.Scope | Env>>(this: Effect.Effect<...>, ab: (_: Effect.Effect<OutDone, OutErr, Env>) => Effect.Effect<OutDone, OutErr, Env>, bc: (_: Effect.Effect<OutDone, OutErr, Env>) => Effect.Effect<Fiber.Fiber<OutDone, OutErr>, never, Scope.Scope | Env>): Effect.Effect<...> (+21 overloads)pipe(
import EffectEffect.const onExit: {
<A, E, XE = never, XR = never>(
f: (
exit: Exit.Exit<A, E>
) => Effect<void, XE, XR>
): <R>(
self: Effect<A, E, R>
) => Effect<A, E | XE, R | XR>
<A, E, R, XE = never, XR = never>(
self: Effect<A, E, R>,
f: (
exit: Exit.Exit<A, E>
) => Effect<void, XE, XR>
): Effect<A, E | XE, R | XR>
}
onExit((exit: Exit.Exit<OutDone, OutErr>exit) => import PubSubPubSub.const publish: {
<A>(value: A): (
self: PubSub<A>
) => Effect.Effect<boolean>
<A>(
self: PubSub<A>,
value: A
): Effect.Effect<boolean>
}
publish(const pubsub: PubSub.PubSub<
Take.Take<OutElem, OutErr, OutDone>
>
const pubsub: {
pubsub: PubSub.Atomic<A>;
subscribers: PubSub.Subscribers<A>;
scope: Scope.Closeable;
shutdownHook: Latch.Latch;
shutdownFlag: MutableRef.MutableRef<boolean>;
strategy: PubSub.Strategy<A>;
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; <…;
}
pubsub, exit: Exit.Exit<OutDone, OutErr>exit)),
import EffectEffect.const forkScoped: <
Arg extends
| Effect<any, any, any>
| {
readonly startImmediately?:
| boolean
| undefined
readonly uninterruptible?:
| boolean
| "inherit"
| undefined
}
| undefined = {
readonly startImmediately?:
| boolean
| undefined
readonly uninterruptible?:
| boolean
| "inherit"
| undefined
}
>(
effectOrOptions?: Arg,
options?:
| {
readonly startImmediately?:
| boolean
| undefined
readonly uninterruptible?:
| boolean
| "inherit"
| undefined
}
| undefined
) => [Arg] extends [
Effect<infer _A, infer _E, infer _R>
]
? Effect<Fiber<_A, _E>, never, _R | Scope>
: <A, E, R>(
self: Effect<A, E, R>
) => Effect<Fiber<A, E>, never, R | Scope>
Forks the fiber in a Scope, interrupting it when the scope is closed.
Example (Forking into the current scope)
import { Effect } from "effect"
const backgroundTask = Effect.gen(function*() {
yield* Effect.sleep("5 seconds")
yield* Effect.log("Background task completed")
return "result"
})
const program = Effect.scoped(
Effect.gen(function*() {
const fiber = yield* backgroundTask.pipe(Effect.forkScoped)
// or fork a fiber that starts immediately:
yield* backgroundTask.pipe(Effect.forkScoped({ startImmediately: true }))
yield* Effect.log("Task forked in scope")
yield* Effect.sleep("1 second")
// Fiber will be interrupted when scope closes
return "scope completed"
})
)
forkScoped
)
return const pubsub: PubSub.PubSub<
Take.Take<OutElem, OutErr, OutDone>
>
const pubsub: {
pubsub: PubSub.Atomic<A>;
subscribers: PubSub.Subscribers<A>;
scope: Scope.Closeable;
shutdownHook: Latch.Latch;
shutdownFlag: MutableRef.MutableRef<boolean>;
strategy: PubSub.Strategy<A>;
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; <…;
}
pubsub
})
)