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

Support ReadableStream.from() #3700

Open
MattiasBuelens opened this issue Jul 20, 2023 · 7 comments
Open

Support ReadableStream.from() #3700

MattiasBuelens opened this issue Jul 20, 2023 · 7 comments
Labels
enhancement New feature or request good first issue Something that would be good for new contributors web-api Something that relates to a standard Web API

Comments

@MattiasBuelens
Copy link

MattiasBuelens commented Jul 20, 2023

What is the problem this feature would solve?

Creating a ReadableStream from an array (or any other iterable) requires a lot of boilerplate, as can be seen in these tests and this example.

What is the feature you are proposing to solve the problem?

The Streams standard now has a new utility method ReadableStream.from(asyncIterable), which adapts any sync or async iterable into a ReadableStream. Once Bun supports this method, creating a ReadableStream from an array would become a one-liner.

Specification: https://streams.spec.whatwg.org/#rs-from
Spec change: whatwg/streams#1083
WPT tests: web-platform-tests/wpt#27009

Deno and Node.js also recently implemented this new method, see denoland/deno#19446 and nodejs/node#48395.

Since Bun is powered by JavaScriptCore, you may also want to look into their pull request: WebKit/WebKit#12454

What alternatives have you considered?

No response

@MattiasBuelens MattiasBuelens added the enhancement New feature or request label Jul 20, 2023
@robobun robobun added the web-api Something that relates to a standard Web API label Jul 20, 2023
@paperdave paperdave added the good first issue Something that would be good for new contributors label Aug 3, 2023
@paperdave
Copy link
Member

This should be easy for us to add. The implementation of it is just copy pasting what they do into our readable stream files. We use TS instead of JS is the main difference i think.

@sravan-s
Copy link

sravan-s commented Aug 4, 2023

Hey @paperdave is it cool if I work on this?

@paperdave
Copy link
Member

go for it. with the builtin functions right now you have to run make regenerate-bindings && make link to see changes reflected. (even though some internal docs say it reloads without this recompile, that doesn't extend to those just yet)

@birkskyum
Copy link
Collaborator

birkskyum commented Aug 24, 2023

Likely fixed by bun 0.8 - @MattiasBuelens is it working for you now?

@MattiasBuelens
Copy link
Author

@birkskyum Unfortunately no, bun 0.8 doesn't support this yet.

$ bun --version
0.8.1
$ cat index.ts
let rs = ReadableStream.from(["a", "b"]);
for await (const x of rs) {
        console.log(x);
}
console.log("done!");
$ bun run index.ts
1 | let rs = ReadableStream.from(["a", "b"]);
            ^
TypeError: ReadableStream.from is not a function. (In 'ReadableStream.from(["a", "b"])', 'ReadableStream.from' is undefined)
      at index.ts:1:9

@birkskyum
Copy link
Collaborator

Okay - the bun docs state that ReadableStream is fully implemented. Doesn't seem to be the case

@MattiasBuelens
Copy link
Author

Hence why I opened this issue. 😅

Bun "fully supports" the Streams standard, but not yet the latest version of the standard. Streams is a living standard, which means new features are still being added. Browsers and runtimes need some time to catch up and implement the latest changes. That's totally fine, and expected.

For browsers and Node.js, you can track their progress on https://wpt.fyi/. For example, at the time of writing, Firefox Nightly and Node.js Nightly already support from(). (It would be cool if Bun had a similar dashboard... 🤔)

jcbhmr added a commit to actions4git/add-commit-push that referenced this issue Nov 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Something that would be good for new contributors web-api Something that relates to a standard Web API
Projects
None yet
Development

No branches or pull requests

5 participants