ASYNCHRONOUS EVENT PROGRAMMING WITH NODE
Andrew ET CS602
EVENT-DRIVEN
Copyright By PowCoder代写 加微信 powcoder
One of Node¡¯s Core Strengths: Faster Processing.
BLOCKING VS
NON BLOCKING
Rather than waiting for an operation to finish, create a callback that will be invoked when the operation ends.
HIGH LEVEL
BLOCKING VS
NON BLOCKING
SINGLE THREADED
The main event loop is single-threaded but most of the I/O runs on separate threads
HIGH LEVEL
Threads run in processes; one process can have many threads in it, and as they are in same process, they share a memory space.
EVENT LOOP
WORKER THREADS
Events are pushed to the main thread then worker threads process the request.
The event loop is implemented via libuv (C++).
Have custom events? Use the events module. const emitter = require(¡°events¡±);
Who else uses EventEmitter class?
EVENT EMITTER NOTES & COMMENTS
The EventEmitter will call all listeners synchronously in
This is important to ensure the proper sequencing of events and to avoid race conditions or logic errors
the order in which they were registered.
Used to raise and handle custom events
EVENT EMITTER
To emit (send) a one-time event myemitter.once()
Calling it again will
do nothing…
EVENT EMITTER UNREGISTER EVENTS
myemitter.off(¡®event¡¯, listener) myemitter.removeListener(¡®event¡¯, listener)
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com