toastStream
Call Signature
Section titled “Call Signature”function toastStream<TYield, TReturn>(source, data?): Promise<StreamResult<TYield, TReturn>>;Defined in: toast-stream.ts:386
Like toast.promise but for iterables/generators/streams.
Blocking/awaitable API: waits until the stream completes and resolves to
{ items, returnValue }. Use this when the caller should wait for all
streamed values before continuing.
Handles: loading → streaming → success/error.
Supports sync and async sources. Captures generator return values. Accepts either an instance or a factory function.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
TYield |
TReturn |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
source |
| AsyncGenerator<TYield, TReturn, unknown> | (() => AsyncGenerator<TYield, TReturn, unknown>) |
data? |
ToastStreamData<TYield, TReturn> |
Returns
Section titled “Returns”Promise<StreamResult<TYield, TReturn>>
Examples
Section titled “Examples”Async generator with progress and return value
import { toastStream } from "@xtandard/lib/sonner";
async function* importUsers() { yield { id: 1, name: "Ada" }; yield { id: 2, name: "Grace" }; return { imported: 2 };}
const { items, returnValue } = await toastStream(importUsers, { loading: "Importing users...", streaming: ({ count, latest }) => `Imported ${count}: ${latest.name}`, success: ({ count, returnValue }) => `Imported ${count} users (${returnValue.imported} confirmed)`, error: (error, partial) => `Import failed after ${partial.count} users: ${String(error)}`,});Sync iterable with artificial delay
const result = await toastStream(["parse", "validate", "save"], { loading: "Starting...", streaming: ({ latest }) => `Running ${latest}`, success: ({ count }) => `Completed ${count} steps`, delay: { first: 300, items: 200, result: 150 },});Call Signature
Section titled “Call Signature”function toastStream<TYield, TReturn>(source, data?): Promise<StreamResult<TYield, TReturn>>;Defined in: toast-stream.ts:394
Sync Generator with return value
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
TYield |
TReturn |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
source |
| Generator<TYield, TReturn, unknown> | (() => Generator<TYield, TReturn, unknown>) |
data? |
ToastStreamData<TYield, TReturn> |
Returns
Section titled “Returns”Promise<StreamResult<TYield, TReturn>>
Call Signature
Section titled “Call Signature”function toastStream<TYield, TReturn>(source, data?): Promise<StreamResult<TYield, TReturn>>;Defined in: toast-stream.ts:400
AsyncChannel with return type - must come before AsyncIterable overload
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
TYield |
TReturn |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
source |
| AsyncChannel<TYield, TReturn> | (() => AsyncChannel<TYield, TReturn>) |
data? |
ToastStreamData<TYield, TReturn> |
Returns
Section titled “Returns”Promise<StreamResult<TYield, TReturn>>
Call Signature
Section titled “Call Signature”function toastStream<TYield>(source, data?): Promise<StreamResult<TYield, void>>;Defined in: toast-stream.ts:406
AsyncIterable (no return value)
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
TYield |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
source |
| AsyncIterable<TYield, any, any> | (() => AsyncIterable<TYield>) |
data? |
ToastStreamData<TYield, void> |
Returns
Section titled “Returns”Promise<StreamResult<TYield, void>>
Call Signature
Section titled “Call Signature”function toastStream<TYield>(source, data?): Promise<StreamResult<TYield, void>>;Defined in: toast-stream.ts:412
AsyncIterator (no return value)
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
TYield |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
source |
| AsyncIterator<TYield, any, any> | (() => AsyncIterator<TYield>) |
data? |
ToastStreamData<TYield, void> |
Returns
Section titled “Returns”Promise<StreamResult<TYield, void>>
Call Signature
Section titled “Call Signature”function toastStream<TYield>(source, data?): Promise<StreamResult<TYield, void>>;Defined in: toast-stream.ts:418
Sync Iterable (no return value)
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
TYield |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
source |
Iterable<TYield, any, any> | (() => Iterable<TYield>) |
data? |
ToastStreamData<TYield, void> |
Returns
Section titled “Returns”Promise<StreamResult<TYield, void>>
Call Signature
Section titled “Call Signature”function toastStream<TYield>(source, data?): Promise<StreamResult<TYield, void>>;Defined in: toast-stream.ts:424
Sync Iterator (no return value)
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
TYield |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
source |
Iterator<TYield, any, any> | (() => Iterator<TYield>) |
data? |
ToastStreamData<TYield, void> |
Returns
Section titled “Returns”Promise<StreamResult<TYield, void>>