Reputation: 322
This likely would happen to other async functions, but I'm using readline
as an example, as that's the issue I encountered.
I've just started using JS and is currently trying to collect input from a file via stdin(<
). An example would be the code below:
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});
rl.on('line', foo);
function foo(line) {
// Code to be iterated by line
}
function summary() {
// Code to be executed after rl finishes
}
So the question is, where do I put summary
function? Does rl.on
take another callback that is executed after it finishes?
Clarification: foo
is called each time when rl
reads a line and summary
is called only once, which is after rl
finishes
Upvotes: 2
Views: 1819
Reputation: 30481
You are probably looking for close event:
rl.on('close', summary);
Upvotes: 4