Process Lifecycle · Level 2 of 8

Last orders can book more

A 'beforeExit' listener that books one more timer, only the first time.

let again = true;process.on('beforeExit', () => {  console.log('beforeExit');  if (again) {    again = false;    setTimeout(() => console.log('one more order'), 10);  }});process.on('exit', () => console.log('exit'));console.log('main done');

1. Predict the output

Tap the lines in the order you think they print.

  1. 1…
  2. 2…
  3. 3…
  4. 4…
  5. 5…