Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

"Keypress" not working when we await answer to a "question" placed in a promise  #42800

Copy link
Copy link
@0xARROWK

Description

@0xARROWK
Issue body actions

Version

v16.13.0

Platform

Ubuntu 18.04

Subsystem

No response

What steps will reproduce the bug?

Hello, I have to use keypress after asking a question to a user. For those 2 actions I use readline as follow :

import readline from "readline";

const menu = readline.createInterface({input: process.stdin, output: process.stdout});
let answer = 0;

const myFunc = async () => {
    return new Promise((resolve, reject) => {
        menu.question('Choose an exchange to use : ', function (answer) {
            if (isNaN(answer) || parseInt(answer) < 1 || parseInt(answer) > 10) answer = undefined;
            menu.close();
            resolve(answer);
        });
    });
}

answer = await myFunc();

readline.emitKeypressEvents(process.stdin)
process.stdin.setRawMode(true);
process.stdin.on('keypress', async (character, key) => {
    if (key.name === 'c' && key.ctrl) {
        process.exit()
    }

    if (key.name === '1' || key.name === '2' || key.name === '3' || key.name === '4') {
        console.log(key.name)
    }
});

But I have notice that keypress event is definitely not working when I ask a question before. If I just remove the question part, it works as expected.

How often does it reproduce? Is there a required condition?

It always happens when the condition of asking a question before is respected. I have noticed that when I remove "await" before the function call, it works as expected

What is the expected behavior?

The expected behaviour is : program print "1", "2", "3", "4", when I hit one of these keys, or exit when I hit ctrl+c

What do you see instead?

Instead I see nothing and program doesn't exit.

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.