PacktPublishing/Node.js-Design-Patterns-Third-Edition

Interpretation of figure 4.3

mananamenos opened this issue · 0 comments

Hi. The figure 4.3 and its explanation is very confusing, at least for me.

  1. When the asynchronous operation of Task 1 is completed, the event loop gives control to it. When Task 1 completes its internal synchronous processing as well, it notifies the Main function.
  1. When the asynchronous operation triggered by Task 2 is complete, the event loop invokes its callback, giving control back to Task 2. At the end of Task 2, the Main function is notified once more. At this point, the Main function knows that both Task 1 and Task 2 are complete, so it can continue its execution or return the results of the operations to another callback.

How does task 2 or task 3 notify the Main function? Once the Main function runs task 1 and task 2 it terminates its execution stack and everything from that point will be called from event loop. Main function cannot be recalled from dead and ... can continue its execution or return the results of the operations to another callback.

So do authors mean with "notify Main function"?