toastStreamAsync
Call Signature
Section titled “Call Signature”function toastStreamAsync<TYield, TReturn>(source, data?): ToastStreamReturn<TYield, TReturn>;Defined in: toast-stream.ts:554
Non-blocking version that returns immediately, in the spirit of
toast.promise(...).unwrap(). Returns { id, unwrap }: the toast id, and an
unwrap() method to await the result later. If you never call unwrap(), a
failed stream only shows the error toast (no unhandled rejection).
Accepts either an instance or a factory function.
Use this when the UI should continue immediately while the toast tracks the stream in the background.
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”ToastStreamReturn<TYield, TReturn>
Examples
Section titled “Examples”import { toastStreamAsync } from "@xtandard/lib/sonner";
const imported = toastStreamAsync(importUsers, { loading: "Importing users...", streaming: ({ count }) => `Imported ${count}`, success: ({ count }) => `Imported ${count} users`,});
// The caller continues immediately; await only if/when the result matters.const { items, returnValue } = await imported.unwrap();// imported.id is Sonner's toast id, e.g. for toast.dismiss(imported.id)Fire-and-track with error handling
const upload = toastStreamAsync(uploadFiles(files), { loading: "Uploading...", streaming: ({ count }) => `${count} files uploaded`, error: (error, partial) => `Upload failed after ${partial.count} files: ${String(error)}`,});
upload.unwrap().catch((error) => { reportError(error);});Call Signature
Section titled “Call Signature”function toastStreamAsync<TYield, TReturn>(source, data?): ToastStreamReturn<TYield, TReturn>;Defined in: toast-stream.ts:562
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”ToastStreamReturn<TYield, TReturn>
Call Signature
Section titled “Call Signature”function toastStreamAsync<TYield, TReturn>(source, data?): ToastStreamReturn<TYield, TReturn>;Defined in: toast-stream.ts:568
AsyncChannel with return type
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”ToastStreamReturn<TYield, TReturn>
Call Signature
Section titled “Call Signature”function toastStreamAsync<TYield>(source, data?): ToastStreamReturn<TYield, void>;Defined in: toast-stream.ts:574
AsyncIterable - excludes AsyncChannel which has its own overload
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
TYield |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
source |
| AsyncIterable<TYield, any, any> | (() => AsyncIterable<TYield, any>) |
data? |
ToastStreamData<TYield, void> |
Returns
Section titled “Returns”ToastStreamReturn<TYield, void>
Call Signature
Section titled “Call Signature”function toastStreamAsync<TYield>(source, data?): ToastStreamReturn<TYield, void>;Defined in: toast-stream.ts:582
AsyncIterator
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”ToastStreamReturn<TYield, void>
Call Signature
Section titled “Call Signature”function toastStreamAsync<TYield>(source, data?): ToastStreamReturn<TYield, void>;Defined in: toast-stream.ts:588
Sync Iterable
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”ToastStreamReturn<TYield, void>
Call Signature
Section titled “Call Signature”function toastStreamAsync<TYield>(source, data?): ToastStreamReturn<TYield, void>;Defined in: toast-stream.ts:594
Sync Iterator
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”ToastStreamReturn<TYield, void>