Skip to content

Simplify async iterator types #61733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 66 additions & 11 deletions src/lib/dom.asynciterable.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,77 @@
/// Window Async Iterable APIs
/////////////////////////////

interface FileSystemDirectoryHandleAsyncIterator<T> extends AsyncIteratorObject<T, BuiltinIteratorReturn, unknown> {
[Symbol.asyncIterator](): FileSystemDirectoryHandleAsyncIterator<T>;
}
/**
* Generic async iterable iterator type that conforms to both
* AsyncIterator and AsyncIterable protocols.
*/
type AsyncIterableIterator<T> = AsyncIterator<T, void, unknown> & {
[Symbol.asyncIterator](): AsyncIterableIterator<T>;
};

// ==========================
// File System Access API
// ==========================

/**
* Represents a handle to a file or directory.
* Extend this interface based on actual implementation or spec.
*/
interface FileSystemHandle {} // Placeholder for real handle definition

/**
* Represents a directory handle capable of returning async iterators
* for entries (key-value pairs), keys (file/directory names), and values (handles).
*/
interface FileSystemDirectoryHandle {
[Symbol.asyncIterator](): FileSystemDirectoryHandleAsyncIterator<[string, FileSystemHandle]>;
entries(): FileSystemDirectoryHandleAsyncIterator<[string, FileSystemHandle]>;
keys(): FileSystemDirectoryHandleAsyncIterator<string>;
values(): FileSystemDirectoryHandleAsyncIterator<FileSystemHandle>;
/**
* Default async iterator over [name, handle] pairs.
*/
[Symbol.asyncIterator](): AsyncIterableIterator<[string, FileSystemHandle]>;

/**
* Returns an async iterator over [name, handle] pairs.
*/
entries(): AsyncIterableIterator<[string, FileSystemHandle]>;

/**
* Returns an async iterator over file/directory names (keys).
*/
keys(): AsyncIterableIterator<string>;

/**
* Returns an async iterator over file/directory handles (values).
*/
values(): AsyncIterableIterator<FileSystemHandle>;
}

interface ReadableStreamAsyncIterator<T> extends AsyncIteratorObject<T, BuiltinIteratorReturn, unknown> {
[Symbol.asyncIterator](): ReadableStreamAsyncIterator<T>;
// ==========================
// ReadableStream API
// ==========================

/**
* Options for customizing the behavior of ReadableStream async iteration.
*/
interface ReadableStreamIteratorOptions {
/**
* If true, prevents canceling the stream when iteration ends early.
*/
preventCancel?: boolean;
}

/**
* Extends ReadableStream with async iteration support via Symbol.asyncIterator
* and the `values()` method. This enables for-await-of streaming of chunks.
*/
interface ReadableStream<R = any> {
[Symbol.asyncIterator](options?: ReadableStreamIteratorOptions): ReadableStreamAsyncIterator<R>;
values(options?: ReadableStreamIteratorOptions): ReadableStreamAsyncIterator<R>;
/**
* Returns an async iterator over stream chunks.
*/
[Symbol.asyncIterator](options?: ReadableStreamIteratorOptions): AsyncIterableIterator<R>;

/**
* Returns an async iterator over stream chunks.
* Functionally identical to Symbol.asyncIterator().
*/
values(options?: ReadableStreamIteratorOptions): AsyncIterableIterator<R>;
}
Loading