k6
k6 copied to clipboard
Support to init a ReadableStream from a io.Reader
What?
It exposes a mechanism from streams (Go) package to initialize a new ReadableStream from a io.Reader:
NewReadableStreamForReader(vu modules.VU, reader io.Reader) *goja.Object
Why?
Because this would makes it possible to reuse the ReadableStream implementation added in v0.51.0 from Go code, so other pieces in k6 (or any k6 extension) that have a Go io.Reader and want to translate to a ReadableStream, usable from JS code, could it.
Checklist
- [X] I have performed a self-review of my code.
- [ ] I have added tests for my changes.
- [ ] I have run linter locally (
make lint) and all checks pass. - [ ] I have run tests locally (
make tests) and all tests pass. - [ ] I have commented on my code, particularly in hard-to-understand areas.
Related PR(s)/Issue(s)
N/A
I think this is great 🚀 🚀 🚀
This is an idea I wanted to bring up here, but I'm not suggesting we should do it, consider it blocking, nor even arguing this is a good idea: I often find myself creating NewSomething() *goja.Object, and NewSomethingFrom(goja.Value) functions when working in extensions. A while ago, when working in WebCrypto, I experimented with the idea of leveraging Go generics to create From and To generic traits.
However, we ended up not needing generics at the time. I wonder if this idea would make sense in such a context, where for a type T, we can implement a trait To[T] *goja.Object and From(goja.Value) *T.
This is somewhat blurry in my head, but I keep thinking about it. Maybe this is something we could try in the future, although I'm not yet certain if it would have benefits beyond creating a contract for creating from and exporting as object given types (and I might be biased by Rust, where this would likely be the way to go in a lot of situations).
I don't know, but if you have thoughts, I'd love to hear them 😄