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 unref readline? #36154

Closed
szmarczak opened this issue Nov 17, 2020 · 9 comments · Fixed by #38019
Closed

How to unref readline? #36154

szmarczak opened this issue Nov 17, 2020 · 9 comments · Fixed by #38019
Labels
doc Issues and PRs related to the documentations. good first issue Issues that are suitable for first-time contributors. readline Issues and PRs related to the built-in readline module.

Comments

@szmarczak
Copy link
Member

Is your feature request related to a problem? Please describe.

const readline = require('readline');

const input = readline.createInterface({
	input: process.stdin
});

The code above just hangs.

Describe the solution you'd like

const readline = require('readline');

const input = readline.createInterface({
	input: process.stdin
});

+input.unref();

Describe alternatives you've considered

None yet.

@szmarczak
Copy link
Member Author

Solved via process.stdin.unref();

@szmarczak
Copy link
Member Author

Although I think it would be nice to add this to docs, so I'll reopen.

@szmarczak szmarczak reopened this Nov 17, 2020
@ZYSzys ZYSzys added doc Issues and PRs related to the documentations. good first issue Issues that are suitable for first-time contributors. readline Issues and PRs related to the built-in readline module. labels Nov 19, 2020
@RaisinTen
Copy link
Contributor

RaisinTen commented Nov 20, 2020

@szmarczak I think instead of hanging, the program is waiting for the end of stdin.
If you start logging what the program reads like the docs say, you will see that it comes to an end after the input is over:

const readline = require('readline');

const input = readline.createInterface({
    input: process.stdin
});

input.on('line', (line) => {
    console.log(line);
})

Here is the log of a run:

time echo 'here is a line'|node index
here is a line
echo 'here is a line'  0.00s user 0.00s system 33% cpu 0.002 total
node index  0.07s user 0.02s system 63% cpu 0.140 total

@danielglazer
Copy link

@szmarczak if still need to address this issue and add this functionality to the doc I would like to take this and open a PR.
Just want to make sure what is being asked... in this API doc I need to add an example as you described? can you maybe give me any advice about in which section do you think that it would be wise to add this example to?

@szmarczak
Copy link
Member Author

At the end of readline.createInterface(options) section

@vbinithyanandamv
Copy link

vbinithyanandamv commented Dec 9, 2020

I have added the example. Please let me know if it needs an update.

@AnupamaP
Copy link
Contributor

@aduh95 I see your review on the referenced PR, I can open a new PR addressing your comments there. Can I be assigned to this?

@aduh95
Copy link
Contributor

aduh95 commented Mar 31, 2021

@AnupamaP By all means, go for it :)

@AnupamaP
Copy link
Contributor

AnupamaP commented Apr 1, 2021

@aduh95 thanks, would appreciate your thoughts on my PR :)

@aduh95 aduh95 closed this as completed in 7980d7c Apr 3, 2021
MylesBorins pushed a commit that referenced this issue Apr 4, 2021
PR-URL: #38019
Fixes: #36154
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
MylesBorins pushed a commit that referenced this issue Apr 5, 2021
PR-URL: #38019
Fixes: #36154
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
targos pushed a commit that referenced this issue May 1, 2021
PR-URL: #38019
Fixes: #36154
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. good first issue Issues that are suitable for first-time contributors. readline Issues and PRs related to the built-in readline module.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants