Section 1

Preview this deck

How do we introduce asynchrony?

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 1, 2020

Cards (11)

Section 1

(11 cards)

How do we introduce asynchrony?

Front

- process.nextTick() - process.setImmediate()

Back

Discuss error propagation

Front

- in synchronous code use throw statements - in asynchronous code pass as first argument to the next callback in the chain

Back

Tip: propagate errors as Error class and as the first argument

Front

- conform to Node convention

Back

What is a module

Front

it is a self contained bit of javascript that can be accessed by require() to be used elsewhere

Back

Tip: when designing API don't release Zalgo

Front

- consistency is key - stay either sync or async - document as such

Back

Why does throw statement not work when used inside a callback supplied to an async funtion?

Front

- because when it is thrown, the callback is in a different stack - inside the event loop (libuv) - causing it to jump up the event look and never gets propagated to the callback

Back

How do we prepare for uncaught errors in our code?

Front

- node emits an 'uncaughtException' event - process.on("uncaughtException", callback) - include process.exit(1); at end of callback - uncaught errors leads to an inconsistent state of the application

Back

Discuss about eventListeners

Front

- it is a class in Node - it provides a channel for events to be dispatched - it provides listeners to be notified

Back

Tip: callbacks are last on parameter list

Front

- conform to Node convention

Back

List Node's event loop steps

Front

- loads a script in its entirety line by line - if there's more to do, wait for something to happen - call callback functions when that something happens - if there's anything left to do or wait for, repeat step 2; otherwise terminate program

Back

List conditions for a Node program to exit

Front

- when there's nothing left to do or to wait for - uncaught exceptions - terminated by user

Back