Node.js Asynchronous Programming with Callbacks and Error Handling, Essays (university) of Software Project Management

An overview of node.js asynchronous programming using callbacks and error handling. It covers the concepts of first-class functions and closures, asynchronous vs synchronous programming, and the event loop in node.js. Learn about long running computations and i/o operations, and how node.js handles callbacks and timers.

Typology: Essays (university)

2017/2018

Uploaded on 03/21/2018

muneeba-kaleem
muneeba-kaleem 🇵🇰

3.7

(3)

4 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Node%Modules:%Callbacks%and%Error%
Handling
Jogesh%K.%Muppala
pf3
pf4
pf5

Partial preview of the text

Download Node.js Asynchronous Programming with Callbacks and Error Handling and more Essays (university) Software Project Management in PDF only on Docsity!

Node Modules: Callbacks and Error

Handling

Jogesh K. Muppala

Two Salient Features of JavaScript

• First-class functions: A function can be treated the

same way as any other variable

• Closures:

– A function defined inside another function has access to all

the variables declared in the outer function (outer scope)

– The inner function will continue to have access to the

variables from the outer scope even after the outer

function has returned

Node, Async I/O and Callbacks

Event Loop (single thread) requests File/ Database/ Processing I/O request Callback I/O request completion

Event Loop

timers I/O callbacks idle, prepare poll check close callbacks incoming: connections, data, etc.

  • timers : this phase executes callbacks scheduled by setTimeout() and setInterval().
  • I/O callbacks : executes almost all callbacks with the exception of close callbacks, the ones scheduled by timers, and setImmediate().
  • idle, prepare : only used internally.
  • poll : retrieve new I/O events; node will block here when appropriate.
  • check : setImmediate() callbacks are invoked here.
  • close callbacks : e.g. socket.on('close', ...).