The
'pause' event is emitted when one of the following occur:
a. The input stream is
paused.
b. The input stream is
not paused and receives the 'SIGCONT' event.
The
listener function is called without passing any arguments.
Example
rl.on('pause',
() => {
console.log('Readline paused.');
});
Find
the below working application.
/* Import readline module */ var readline = require('readline'); /* * create a new readline.Interface instance that reads data from standard input * and write data to standard output */ var rl = readline.createInterface({ input: process.stdin, output: process.stdout }); // Adding close and pause events /* Add a callback function on readline.Interface instance close event */ rl.on('close', function(){ console.log("Close event received"); }); /* Add a callback function on readline.Interface instance pause event */ rl.on('pause', () => { console.log('Readline paused.'); }); /* Ask a question to the user and print the received answer */ rl.question("Enter something ", function(data){ console.log("You entered %s", data); rl.close() });
Output
Enter
something Hello World
You
entered Hello World
Readline
paused.
Close
event received
No comments:
Post a Comment