<A, E>(queue: Queue.Dequeue<A, E>): Stream<A, Exclude<E, Cause.Done>>Creates a stream that pulls values from a Queue.Dequeue.
Details
The stream emits non-empty batches of queued values and ends when the queue
fails with Cause.Done; other queue failures are propagated.
Example (Creating a stream from a queue of values)
import { Console, Effect, Queue, Stream } from "effect"
const program = Effect.gen(function*() {
const queue = yield* Queue.unbounded<number>()
yield* Queue.offer(queue, 1)
yield* Queue.offer(queue, 2)
yield* Queue.offer(queue, 3)
yield* Queue.shutdown(queue)
const stream = Stream.fromQueue(queue)
const values = yield* Stream.runCollect(stream)
yield* Console.log(values)
})
Effect.runPromise(program)
// Output: [ 1, 2, 3 ]export const const fromQueue: <A, E>(
queue: Queue.Dequeue<A, E>
) => Stream<A, Exclude<E, Cause.Done>>
Creates a stream that pulls values from a Queue.Dequeue.
Details
The stream emits non-empty batches of queued values and ends when the queue
fails with Cause.Done; other queue failures are propagated.
Example (Creating a stream from a queue of values)
import { Console, Effect, Queue, Stream } from "effect"
const program = Effect.gen(function*() {
const queue = yield* Queue.unbounded<number>()
yield* Queue.offer(queue, 1)
yield* Queue.offer(queue, 2)
yield* Queue.offer(queue, 3)
yield* Queue.shutdown(queue)
const stream = Stream.fromQueue(queue)
const values = yield* Stream.runCollect(stream)
yield* Console.log(values)
})
Effect.runPromise(program)
// Output: [ 1, 2, 3 ]
fromQueue = <function (type parameter) A in <A, E>(queue: Queue.Dequeue<A, E>): Stream<A, Exclude<E, Cause.Done>>A, function (type parameter) E in <A, E>(queue: Queue.Dequeue<A, E>): Stream<A, Exclude<E, Cause.Done>>E>(queue: Queue.Dequeue<A, E>(parameter) queue: {
strategy: "suspend" | "dropping" | "sliding";
dispatcher: SchedulerDispatcher;
capacity: number;
messages: MutableList.MutableList<any>;
state: Queue.State<any, any>;
scheduleRunning: boolean;
toString: () => string;
toJSON: () => unknown;
}
queue: import QueueQueue.interface Dequeue<out A, out E = never>A Dequeue is a queue that can be taken from.
Details
This interface represents the read-only part of a Queue, allowing you to take
elements from the queue but not offer elements to it.
Example (Taking through dequeue handles)
import { Effect, Queue } from "effect"
const program = Effect.gen(function*() {
const queue = yield* Queue.bounded<string, never>(10)
// A Dequeue can only take elements
const dequeue: Queue.Dequeue<string> = queue
// Pre-populate the queue
yield* Queue.offerAll(queue, ["a", "b", "c"])
// Take elements using dequeue interface
const item = yield* Queue.take(dequeue)
console.log(item) // "a"
})
Companion namespace containing type-level metadata for the Dequeue
read-only queue interface.
Dequeue<function (type parameter) A in <A, E>(queue: Queue.Dequeue<A, E>): Stream<A, Exclude<E, Cause.Done>>A, function (type parameter) E in <A, E>(queue: Queue.Dequeue<A, E>): Stream<A, Exclude<E, Cause.Done>>E>): interface Stream<out A, out E = never, out R = never>A Stream<A, E, R> describes a program that can emit many A values, fail
with E, and require R.
Details
Streams are pull-based with backpressure and emit chunks to amortize effect
evaluation. They support monadic composition and error handling similar to
Effect, adapted for multiple values.
Example (Creating and consuming streams)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
yield* Stream.make(1, 2, 3).pipe(
Stream.map((n) => n * 2),
Stream.runForEach((n) => Console.log(n))
)
})
Effect.runPromise(program)
// Output:
// 2
// 4
// 6
Stream<function (type parameter) A in <A, E>(queue: Queue.Dequeue<A, E>): Stream<A, Exclude<E, Cause.Done>>A, type Exclude<T, U> = T extends U
? never
: T
Exclude from T those types that are assignable to U
Exclude<function (type parameter) E in <A, E>(queue: Queue.Dequeue<A, E>): Stream<A, Exclude<E, Cause.Done>>E, import CauseCause.interface Done<A = void>A graceful completion signal for queues and streams.
When to use
Use to model normal producer completion through a stream or queue error
channel.
Details
Done indicates that a producer has finished normally — no more elements
will arrive. It is distinct from an error or interruption; it represents
successful completion. The optional value field can carry a final
leftover payload.
Example (Signaling queue completion)
import { Cause, Effect, Queue } from "effect"
const program = Effect.gen(function*() {
const queue = yield* Queue.bounded<number, Cause.Done>(10)
yield* Queue.offer(queue, 1)
yield* Queue.end(queue)
const result = yield* Effect.flip(Queue.take(queue))
console.log(Cause.isDone(result)) // true
})
Companion namespace for the Done interface.
Creates a Done signal with an optional value.
When to use
Use when you need to construct a low-level pull completion signal directly.
Done>> =>
const fromChannel: <
Arr extends Arr.NonEmptyReadonlyArray<any>,
E,
R
>(
channel: Channel.Channel<
Arr,
E,
void,
unknown,
unknown,
unknown,
R
>
) => Stream<
Arr extends Arr.NonEmptyReadonlyArray<infer A>
? A
: never,
E,
R
>
Creates a stream from a array-emitting Channel.
Example (Creating a stream from an array-emitting channel)
import { Channel, Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
const channel = Channel.succeed([1, 2, 3] as const)
const stream = Stream.fromChannel(channel)
const result = yield* Stream.runCollect(stream)
yield* Console.log(result)
})
// Output: [ 1, 2, 3 ]
fromChannel(import ChannelChannel.const fromQueueArray: <A, E>(
queue: Queue.Dequeue<A, E>
) => Channel<
Arr.NonEmptyReadonlyArray<A>,
Exclude<E, Cause.Done>
>
Creates a channel from a queue that emits arrays of elements.
Example (Creating batched channels from queues)
import { Channel, Data, Effect, Queue } from "effect"
class ProcessingError extends Data.TaggedError("ProcessingError")<{
readonly stage: string
}> {}
const program = Effect.gen(function*() {
// Create a queue for batch processing
const queue = yield* Queue.bounded<number, ProcessingError>(100)
// Fill queue with data
yield* Queue.offerAll(queue, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
// Create a channel that reads arrays from the queue
const arrayChannel = Channel.fromQueueArray(queue)
// This will emit non-empty arrays of elements instead of individual items
// Useful for batch processing scenarios
return arrayChannel
})
// High-throughput processing example
const batchProcessor = Effect.gen(function*() {
const dataQueue = yield* Queue.dropping<string, ProcessingError>(1000)
const batchChannel = Channel.fromQueueArray(dataQueue)
// Process data in batches for better performance
return Channel.map(
batchChannel,
(batch) => batch.map((item) => item.toUpperCase())
)
})
fromQueueArray(queue: Queue.Dequeue<A, E>(parameter) queue: {
strategy: "suspend" | "dropping" | "sliding";
dispatcher: SchedulerDispatcher;
capacity: number;
messages: MutableList.MutableList<any>;
state: Queue.State<any, any>;
scheduleRunning: boolean;
toString: () => string;
toJSON: () => unknown;
}
queue))