ConstAsyncIterableSchema.parse(
(async function* () {
yield 1;
})(),
); // ✓ Valid (async generator)
AsyncIterableSchema.parse(Readable.from([1, 2, 3])); // ✓ Valid (Node stream)
AsyncIterableSchema.parse(new ReadableStream()); // ✓ Valid (Web stream, Node 22+)
AsyncIterableSchema.parse([1, 2, 3]); // ✗ Throws (sync iterable, not async)
AsyncIterableSchema.parse(Promise.resolve(1)); // ✗ Throws (Promise is not iterable)
import { createAssertion, use } from 'bupkis';
import { AsyncIterableSchema } from 'bupkis/schema';
const asyncIterableAssertion = createAssertion(
[AsyncIterableSchema, 'to be an async iterable'],
AsyncIterableSchema,
);
const { expect } = use([asyncIterableAssertion]);
expect(
(async function* () {
yield 1;
})(),
'to be an async iterable',
);
Schema matching any asynchronous iterable (has
Symbol.asyncIteratormethod).This schema validates values that implement the asynchronous iteration protocol, meaning they have a
Symbol.asyncIteratormethod that returns an async iterator. This includes async generators, Node.js Readable streams (v10+), and Web ReadableStreams (in modern browsers and Node.js v22+).