Single-Threaded thus Asynchronous
Multi-thread vs mono-thread
In a synchronous, multi-threaded and data-driven world, this works:
... but in a single-threaded world, this can lead to trouble as the application would freeze until it receives a response.
Until the function ends (and its callees), no other function can be executed simultaneously.
Asynchronous processing using callbacks
Asynchronous processing advantages
No threads count limitation.
No memory overhead due to threads.
No locks or semaphores.
No greedy locks.
No deadlocks.
Data doesn't change during the execution of a function.
Closures
A closure is the combination of a function definition and the lexical environment in which the latter is defined.
Closures determine the scope of the variables.
Variables can be read and modified in the closure where they are declared but also in the functions defined inside.
Last updated