sindresorhus / hook-std

Hook and modify stdout and stderr
MIT License
54 stars 12 forks source link

Async iterator support #15

Open sindresorhus opened 6 years ago

sindresorhus commented 6 years ago

Could be a nice alternative to the transform callback.

acostalima commented 6 years ago

hey @sindresorhus, I will try to implement this. However, I have some doubts:

acostalima commented 6 years ago

ping @sindresorhus

sindresorhus commented 6 years ago

Thanks for your patience :)

Is the async iterator supposed to replace the transform callback entirely or should we have support for both?

My thinking is that it's just an addition for when you only need to read and not transform.

We cannot pass the output argument to iterator's next(), unless we specify the property value returned by next() should be a function just like transform. What do you think?

We could support transform by returning a function that accepts the new value, indeed, but I think this would be more complicated for the user than just using the existing transform callback, so I think it makes more sense to only support the read-only case.

Is the idea to loop through the iterator until its end per call to .write() or just call next() once?

Per call to .write()

Shall we call unhook() as soon as the iterator's reaches its end?

Yes

acostalima commented 6 years ago

@sindresorhus no worries 😄

Thanks for the feedback. As soon as I have some free time, I'll work on this. 💪