24
Asynchronous programming in Node.js 1

Asynchronous programming in Node - MathUniPDtullio/IS-1/2016/Seminari/Async.pdf · What is Node.js? 5. Event-driven Much of the Node.js core API is built around an idiomatic asynchronous

  • Upload
    others

  • View
    9

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Asynchronous programming in Node - MathUniPDtullio/IS-1/2016/Seminari/Async.pdf · What is Node.js? 5. Event-driven Much of the Node.js core API is built around an idiomatic asynchronous

Asynchronous programming in Node.js

1

Page 2: Asynchronous programming in Node - MathUniPDtullio/IS-1/2016/Seminari/Async.pdf · What is Node.js? 5. Event-driven Much of the Node.js core API is built around an idiomatic asynchronous

Asynchronous programming in Node.js

2

Page 3: Asynchronous programming in Node - MathUniPDtullio/IS-1/2016/Seminari/Async.pdf · What is Node.js? 5. Event-driven Much of the Node.js core API is built around an idiomatic asynchronous

Asynchronous programming

3

Page 4: Asynchronous programming in Node - MathUniPDtullio/IS-1/2016/Seminari/Async.pdf · What is Node.js? 5. Event-driven Much of the Node.js core API is built around an idiomatic asynchronous

Asynchronous programming

4

Page 5: Asynchronous programming in Node - MathUniPDtullio/IS-1/2016/Seminari/Async.pdf · What is Node.js? 5. Event-driven Much of the Node.js core API is built around an idiomatic asynchronous

Asynchronous programming

5

Page 6: Asynchronous programming in Node - MathUniPDtullio/IS-1/2016/Seminari/Async.pdf · What is Node.js? 5. Event-driven Much of the Node.js core API is built around an idiomatic asynchronous

Asynchronous

6

English Definition of

Adjective1. Not occurring at the same time.2. Controlling the timing of operations by the use of pulses sent

when the previous operation is completed rather than at regular intervals.

Source:https://en.oxforddictionaries.com/definition/asynchronous

Page 7: Asynchronous programming in Node - MathUniPDtullio/IS-1/2016/Seminari/Async.pdf · What is Node.js? 5. Event-driven Much of the Node.js core API is built around an idiomatic asynchronous

Asynchronous

7

English Definition of

Adjective1. Not occurring at the same time.2. Controlling the timing of operations by the use of events sent

when the previous operation is completed rather than at regular intervals.

Source: A. Maccagnan

Page 8: Asynchronous programming in Node - MathUniPDtullio/IS-1/2016/Seminari/Async.pdf · What is Node.js? 5. Event-driven Much of the Node.js core API is built around an idiomatic asynchronous

8

One step back

Page 9: Asynchronous programming in Node - MathUniPDtullio/IS-1/2016/Seminari/Async.pdf · What is Node.js? 5. Event-driven Much of the Node.js core API is built around an idiomatic asynchronous

9

What is Node.js?

Page 10: Asynchronous programming in Node - MathUniPDtullio/IS-1/2016/Seminari/Async.pdf · What is Node.js? 5. Event-driven Much of the Node.js core API is built around an idiomatic asynchronous

10

Source: Giacomo Fornari, Flipped classroom. Sistemi Concorrenti e Distribuiti 2016/2017,

http://www.slideshare.net/GiacomoFornari/nodejs-concurrency-68682939.

What is Node.js?

Page 11: Asynchronous programming in Node - MathUniPDtullio/IS-1/2016/Seminari/Async.pdf · What is Node.js? 5. Event-driven Much of the Node.js core API is built around an idiomatic asynchronous

What is Node.js?

● Event-driven● I/O● Server-side● Javascript environment● Based on V8

11

Page 12: Asynchronous programming in Node - MathUniPDtullio/IS-1/2016/Seminari/Async.pdf · What is Node.js? 5. Event-driven Much of the Node.js core API is built around an idiomatic asynchronous

What is Node.js?

5. Event-driven4. I/O3. Server side1. Javascript environment2. Based on V8

12

Page 13: Asynchronous programming in Node - MathUniPDtullio/IS-1/2016/Seminari/Async.pdf · What is Node.js? 5. Event-driven Much of the Node.js core API is built around an idiomatic asynchronous

What is Node.js?

5. Event-driven4. I/O3. Server side1. Javascript environment2. Based on V8

13

Page 14: Asynchronous programming in Node - MathUniPDtullio/IS-1/2016/Seminari/Async.pdf · What is Node.js? 5. Event-driven Much of the Node.js core API is built around an idiomatic asynchronous

What is Node.js?

2. Based on V8

14

Source: https://www.diva-portal.org/smash/get/diva2:550993/FULLTEXT01.pdf

Page 15: Asynchronous programming in Node - MathUniPDtullio/IS-1/2016/Seminari/Async.pdf · What is Node.js? 5. Event-driven Much of the Node.js core API is built around an idiomatic asynchronous

What is Node.js?

5. Event-driven4. I/O3. Server side1. Javascript environment2. Based on V8

15

Page 16: Asynchronous programming in Node - MathUniPDtullio/IS-1/2016/Seminari/Async.pdf · What is Node.js? 5. Event-driven Much of the Node.js core API is built around an idiomatic asynchronous

What is Node.js?

5. Event-driven4. I/O3. Server side1. Javascript environment2. Based on V8

16

Page 17: Asynchronous programming in Node - MathUniPDtullio/IS-1/2016/Seminari/Async.pdf · What is Node.js? 5. Event-driven Much of the Node.js core API is built around an idiomatic asynchronous

What is Node.js?

4. I/O

Source: Understanding the node.js event loop, http://blog.mixu.net/2011/02/01/understanding-the-node-js-event-loop

17

Page 18: Asynchronous programming in Node - MathUniPDtullio/IS-1/2016/Seminari/Async.pdf · What is Node.js? 5. Event-driven Much of the Node.js core API is built around an idiomatic asynchronous

What is Node.js?

5. Event-driven4. I/O3. Server side1. Javascript environment2. Based on V8

18

Page 19: Asynchronous programming in Node - MathUniPDtullio/IS-1/2016/Seminari/Async.pdf · What is Node.js? 5. Event-driven Much of the Node.js core API is built around an idiomatic asynchronous

What is Node.js?

5. Event-drivenMuch of the Node.js core API is built around an idiomatic asynchronous

event-driven architecture in which certain kinds of objects (called

"emitters") periodically emit named events that cause Function objects

("listeners") to be called.

Source:

https://nodejs.org/api/events.html#events_passing_arguments_and_this

_to_listeners

19

Page 20: Asynchronous programming in Node - MathUniPDtullio/IS-1/2016/Seminari/Async.pdf · What is Node.js? 5. Event-driven Much of the Node.js core API is built around an idiomatic asynchronous

What is Node.js?

5. Event-drivenMuch of the Node.js core API is built around an idiomatic asynchronous

event-driven architecture in which certain kinds of objects (called

"emitters") periodically emit named events that cause Function objects

("listeners") to be called.

Source:

https://nodejs.org/api/events.html#events_passing_arguments_and_this

_to_listeners

20

Page 21: Asynchronous programming in Node - MathUniPDtullio/IS-1/2016/Seminari/Async.pdf · What is Node.js? 5. Event-driven Much of the Node.js core API is built around an idiomatic asynchronous

What is Node.js?

5. Event-driven

21

Page 22: Asynchronous programming in Node - MathUniPDtullio/IS-1/2016/Seminari/Async.pdf · What is Node.js? 5. Event-driven Much of the Node.js core API is built around an idiomatic asynchronous

What is Node.js?

5. Event-driven

Source: http://abdelraoof.com/blog/2015/10/28/understanding-nodejs-event-loop

22

Page 23: Asynchronous programming in Node - MathUniPDtullio/IS-1/2016/Seminari/Async.pdf · What is Node.js? 5. Event-driven Much of the Node.js core API is built around an idiomatic asynchronous

Asynchronous programming

23

Must read: http://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-function

Page 24: Asynchronous programming in Node - MathUniPDtullio/IS-1/2016/Seminari/Async.pdf · What is Node.js? 5. Event-driven Much of the Node.js core API is built around an idiomatic asynchronous

ExamplesCode could be found here:

https://github.com/alemhnan/SWE.UNIPD

24