Skip to content
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

Why Iterable / AsyncIterable are not valid body? #2392

Open
1 task done
darksabrefr opened this issue Nov 25, 2024 · 0 comments
Open
1 task done

Why Iterable / AsyncIterable are not valid body? #2392

darksabrefr opened this issue Nov 25, 2024 · 0 comments

Comments

@darksabrefr
Copy link

What would you like to discuss?

Hello,
Currently, the request body option can be, among others types, Generator / AsyncGenerator:
https://github.com/sindresorhus/got/blob/a7b5aec57a0245cafbd21696d52cd6bd6c95628a/source/core/options.ts#L1306-1311

These bodies are used like anything implementing the Iterable / AsyncIterable protocol, via a simple for await..of loop:

got/source/core/index.ts

Lines 969 to 980 in a7b5aec

} else if (is.generator(body) || is.asyncGenerator(body)) {
(async () => {
try {
for await (const chunk of body) {
await this._asyncWrite(chunk);
}
super.end();
} catch (error: any) {
this._beforeError(error);
}
})();

So, the question is: Why not using the more generic Iterable / AsyncIterable instead of Generator / AsyncGenerator, as the differences should be very minor? Is there a limitation somewhere, preventing to do that?

Another benefit would be supporting the web ReadableStreams directly, with no prior conversion.

Checklist

  • I have read the documentation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant