Skip to content

How to unref readline? #36154

Description

@szmarczak

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.

Activity

  1. szmarczak commented on Nov 17, 2020

    @szmarczak
    ContributorAuthor

    Solved via process.stdin.unref();

  2. szmarczak commented on Nov 17, 2020

    @szmarczak
    ContributorAuthor

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

  3. added
    docIssues and PRs related to Node.js documentation.
    good first issueIssues that are suitable for first-time contributors.
    readlineIssues and PRs related to the built-in readline module.
    on Nov 19, 2020
  4. RaisinTen commented on Nov 20, 2020

    @RaisinTen
    Member

    @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
  5. danielglazer commented on Nov 20, 2020

    @danielglazer

    @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?

  6. szmarczak commented on Nov 20, 2020

    @szmarczak
    ContributorAuthor

    At the end of readline.createInterface(options) section

  7. vbinithyanandamv commented on Dec 9, 2020

    @vbinithyanandamv

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

  8. AnupamaP commented on Mar 31, 2021

    @AnupamaP
    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?

  9. aduh95 commented on Mar 31, 2021

    @aduh95
    Contributor

    @AnupamaP By all means, go for it :)

  10. AnupamaP commented on Apr 1, 2021

    @AnupamaP
    Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to Node.js documentation.good first issueIssues that are suitable for first-time contributors.readlineIssues and PRs related to the built-in readline module.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions