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

How to know what is the last line or the index of the iteration? #2

Open
jamg44 opened this issue Jan 27, 2021 · 2 comments
Open

How to know what is the last line or the index of the iteration? #2

jamg44 opened this issue Jan 27, 2021 · 2 comments

Comments

@jamg44
Copy link

jamg44 commented Jan 27, 2021

Is there any way to know what is the last line, or the index of the iteration?

for await (const line of chunksToLinesAsync(stream)) {
    console.log(chomp(line));
}

Thanks for your work!

@rauschma
Copy link
Owner

rauschma commented Feb 3, 2021

@jamg44 You’d have to write your own utilities (e.g. via generators):

  • A function that returns an iterable over [currentValue, nextValue] (the latter being undefined for the last currentValue.
  • A function that returns an iterable over [currentValue, index].

@milahu
Copy link

milahu commented Nov 11, 2021

this sounds similar to my problem:
expose an interactive process (repl) with a json restful apiserver
= connect stdin/stdout streams to request/response buffers

i needed something more "high level" than stringio
and by searching for "capture stdout of interactive child process in nodejs"
i found a stackoverflow question on interactive terminal emulation
aka implementing the TTY protocol in nodejs

@rauschma maybe link to pty and tty as "related projects"?
edit: pty is abandoned since node 8, active fork in node-pty

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

3 participants