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
Event listeners warning on multiple prompts #62
Comments
Technically that code is not compatible with Even if you remove the But I think this is something One way to support this is to have an This will prevent multiple event listeners from being attached (whilst still maintaining the ability for tests to override the stream as the listeners will be attached and removed before and after each prompt in the queue). @SBoudrias I'm bad at explaining things but I hope you got the gist of what I am saying, I'll knock up a pull-request when I get back later today for you to take a look at. |
@SBoudrias Is this still valid? The tests don't override the stream like that any more. |
My use case is to maintain the flow, while navigating between different sections in a script. Something like an old school menu with "select" and "back" options. So it's like "Test 1" (nested calls). I added "Test 2" and "Test 3", because I think a solution to "Test 1" will fix those too and a warning from Node should be prevented in any case (except misuse). Like with errors. The example in ./examples/nested-calls.js is not good for testing nested calls, because there is only one nesting and the warning that this issue is about, is printed only when the nestings are more than nine (with the default "maxListeners" value). Nested calls should be infinite theoretically. Like in "Test 1". |
I completely overlooked your There are 2 bugs here: There is a memory leak (I'll post more details on this below), which will cause all 3 test cases to fail. Even after fixing the memory leak test 2 and 3 will still fail as currently |
The memory leak is something to do with |
// Test 1 (visually better) var inquirer = require('inquirer');
var nestingsCounter = 0;
var maxNestings = 10;
var promptsGroup = function (callback) {
inquirer.prompt([{
type: 'list',
name: 'choice-A' + nestingsCounter,
message: 'Select:',
choices: [
'value-A' + nestingsCounter + '.1',
'value-A' + nestingsCounter + '.2'
]
}, {
type: 'list',
name: 'choice-B' + nestingsCounter,
message: 'Select:',
choices: [
'value-B' + nestingsCounter + '.1',
'value-B' + nestingsCounter + '.2'
]
}], function (answers) {
console.log(
'choice-A%d:',
nestingsCounter,
answers['choice-A' + nestingsCounter]
);
console.log(
'choice-B%d:',
nestingsCounter,
answers['choice-B' + nestingsCounter]
);
console.log('');
nestingsCounter += 1;
if (nestingsCounter <= maxNestings) {
callback(callback);
} else {
console.log('Maximum nested prompts number (%d) reached!', maxNestings);
}
});
};
promptsGroup(promptsGroup); |
The test that I am using at the moment is (no user input required): var inquirer = require('inquirer');
var nestingsCounter = 0;
var maxNestings = 10;
var promptsGroup = function (callback) {
inquirer.prompt([{
type: 'input',
name: 'option' ,
message: 'Nest:',
default: nestingsCounter
}], function (answers) {
nestingsCounter += 1;
if (nestingsCounter <= maxNestings) {
callback(callback);
} else {
console.log('Maximum nested prompts number (%d) reached!', maxNestings);
}
});
console.log("");
inquirer.rl.emit("line");
};
promptsGroup(promptsGroup); |
Nice, so we have a test and an example! |
Since the To fix this leak we need to call mute-stream's By adding |
It works fine now, thanks! |
Call streams end to trigger cleanup (fix #62)
Fix is out on release 0.3.2 Thank you for the report, and thanks to @danielchatfield for the quick fix! |
I've got a mainMenu function that presents the first level of options. Based on the user's choice, they are presented with the relevant submenu (stored in a different function). Some of those submenu options again have a set of related options or input prompts, and so on. I want mainMenu to repeat until the user chooses the "Quit" rawlist option. To achieve this, I recursively call mainMenu() after the switch statement in mainMenu. Unfortunately I know this is killing the stack and causing the error being discussed here. FYI all my functions are async so not using the .then notation. What is the correct way to implement a repeating, multinested menu system in Inquirer? Thanks. Attached my server JS for reference. |
same here :) |
Hello, thanks for this nice module!
When running multiple prompts, I get this warning:
"(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit."
Tests:
The text was updated successfully, but these errors were encountered: