Uh oh!
There was an error while loading. Please reload this page.
stream: add Transform.by utility function - #28501
Conversation
52dc5bd to
e85b78dCompareedit: tests passed on a subsequent run (which was a docs fix), guessing its infrastructure failurethe two failing JS tests seem to be failing due to being run against a binary that doesn't have the compiled changes in... maybe it's a caching thing? |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
mcollina
commented
Jul 2, 2019
Should we ship this as experimental to start? |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
devsnek
commented
Jul 3, 2019
given that https://github.com/tc39/proposal-iterator-helpers is likely to hit stage 2 at the end of this month, and would allow something looking like this: someReadable[Symbol.asyncIterator]().map(async(x)=>{whatever}).forEach((item)=>writable.push(item));perhaps instead of adding this api we should just wait for the iterator methods to mature? |
mcollina
commented
Jul 4, 2019
@devsnek I think the two requirements are orthogonal. This PR is all about enabling async iterators and async functions to "play decently" with the Stream ecosystem of modules. In other term, it enables to "use The added support for the iterator helpers are needed to improve the language overall, but they won't help in improving the Stream ecosystem.
As a side note, I don't see anything specific to |
@mcollina if that is the case this should probably accept any function. (also, all the methods being added for sync iterables are also being added for async iterables, and they propogate errors to the end of the chain) |
@davidmarkclements: When I try to run this locally the test never finishes: out/Release/node test/parallel/test-transform-by.js |
ronag
commented
Dec 16, 2019
This probably got broken by f8018f2 |
There was a problem hiding this comment.
I believe this can be implemented in just a few lines using Readble.from, e.g. nxtedition#12. Passes all tests expect for a few ones I'm not sure are needed (e.g. invalid arg type checks should probably be moved into from).
constfrom=require('internal/streams/from');Transform.by=functionby(asyncGeneratorFn,opts){let_resolve;let_promise=newPromise((resolve)=>_resolve=resolve);returnfrom(Duplex,asyncGeneratorFn(asyncfunction*(){while(true){const{ chunk, done, cb }=await_promise;if(done)returncb();yieldchunk;_promise=newPromise((resolve)=>_resolve=resolve);cb();}}()),{objectMode: true,autoDestroy: true,
...opts,write: (chunk,encoding,cb)=>_resolve({ chunk,done: false, cb }),final: (cb)=>_resolve({done: true, cb })});};ronag
commented
Dec 17, 2019
Any reason why this is not simply called |
davidmarkclements
commented
Dec 17, 2019
The
|
very cool - I noticed some tests were commented out. I think the one for encoding in particular needs to be supported. Can you speak more to why the others are commented out? The checks for whether an async function generator is being passed were added at the request of prior reviews, I'd rather honour those initial requests than vacillate on that. Also, I'd be interested in the performance impact of each approach. |
I need to better understand this one. I'll follow up with your comment on the PR.
I agree with them. But I think they should be consistent with and live in
Maybe a benchmark under /benchmark then? |
I made a benchmark but it doesn't work with the version in this PR for some reason? nxtedition@9fbb8d4 |
ronag
commented
Dec 17, 2019
I'm not sure what the best course of action here is. @davidmarkclements would you be interested in cherry-picking my proposed changes into this PR? |
@mcollina: Is this something we still want considering the recent added functionality in |
mcollina
commented
Feb 9, 2020
I would say so, IMHO it serves a different purpose. |
ronag
commented
Feb 9, 2020
@davidmarkclements are you still interested in continuing work on this PR or would you mind if I took over? |
8ae28ff to
2935f72Comparejasnell
commented
Jul 7, 2020
Ping @davidmarkclements ... still want to do this? |
davidmarkclements
commented
Sep 24, 2020
@jasnell I've just remembered I was doing this, can we get it in before v14 goes to Active? |
mcollina
commented
Sep 24, 2020
Yes we can! |
safareli
commented
May 6, 2021
Hi, this looks super nice! Is there any plans to get this merged at some point? |
mcollina
commented
May 6, 2021
@safareli would you like to work on it? I think it just requires somebody willing to update this and do a fresh PR. I don't think @davidmarkclements will work on this. |
safareli
commented
May 15, 2021
ronag
commented
Jul 8, 2021
Closing in favor of #38696 |
Analogous to
Readable.from,Transform.bycreates transform streamsfrom async function generators.
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes