JS Event Loop, Promises, Async Await Etc: Slava Kim
JS Event Loop, Promises, Async Await Etc: Slava Kim
TA
Parallelism vs Concurrency
TA Student
Parallelism vs Concurrency
TA
Parallelism vs Concurrency
TA
Parallelism vs Concurrency
TA
Parallelism vs Concurrency
TA
Parallelism vs Concurrency
TA
Is TA concurrent or parallel?
TA is not parallel - there is only one TA
TA TA
Parallelism vs Concurrency
TA TA
Parallelism vs Concurrency
TA
TA
Parallelism vs Concurrency
TA
TA
Parallelism vs Concurrency
TA
TA
Is TA concurrent or parallel?
There are multiple TAs - we can achieve parallelism with concurrency
Some programming languages allow you to use multiple cores (C++, Java)
JavaScript is single threaded, can only use one core, but is still concurrent
How?
Queue
TA
Queue
TA
Queue
TA
Queue
click
Callbacks to handle a result of an operation
result
Time outs and intervals
timeout
Event Loop
A
C
… (2 second delay)
B
Event Loops example
Event Loops example
A
C
… (virtually no delay)
B
Event Loops: Good
It is a “simple” model to work with to achieve concurrency
Good when you have a lot of I/O work (most web servers, UI systems)
Examples of I/O: talking to database, handling requests, waiting for user to click
Event Loop: bad
CPU intensive operations will bring down your browser/server
Callback hell!
Possible solution with promises
Only one additional level
of nesting
Might need to wrap other libraries into promises interface with “promisify”
Code “reads”
synchronous but
actually is async
Code “reads”
synchronous but
actually is async
[demo]