Index
Overview


We'll learn that we can describe synchronous and asynchronous computing with a single word.

We'll first browse a couple experiments, and then define our Quick Definitions.

Synchronous Experiment


Overview


In this experiment we'll look at "synchronous" computations.

Experiment


In this experiment we call three "normal" functions named "task1", "task2" and "task3".

Each task will log (print) as it is running.
const
	tools = require('./sync'),
	task1 = tools.task1,
	task2 = tools.task2,
	task3 = tools.task3;

task1();
task2();
task3();
Here is the experiment output.

We're looking for the general pattern of the output (not the details).
Output
function1 -- starting
function1 -- working
function1 -- working
function1 -- working
function1 -- finished

function2 -- starting
function2 -- working
function2 -- working
function2 -- working
function2 -- finished

function3 -- starting
function3 -- working
function3 -- working
function3 -- working
function3 -- finished
From the output we can see that when the computation calls "task1" it then waits.
When "task1" finishes, the computation moves to the next operation and calls "task2" and again waits.
Think "wait" for synchronous computation. It is also referred to as "blocking".

It is a type of "sequential computation".


synchronous = wait

Asynchronous Experiment


Overview


In this experiment we'll look at "asynchronous" computations.

Experiment


In this experiment we call three tasks (functions) that will run asynchronously.

Each task will log as it is running.
const
	tools = require('./async'),
	task1 = tools.task1,
	task2 = tools.task2,
	task3 = tools.task3;

task1();
task2();
task3();
Here is the experiment output.

It is much different.

We're for the general pattern of the output (not the details).
task1 -- starting
task2 -- starting
task3 -- starting
task1 -- working
task2 -- working
task3 -- working
task1 -- working
task2 -- working
task3 -- working
task1 -- working
task1 -- finished
task2 -- working
task2 -- finished
task3 -- working
task3 -- finished
The program starts, and from the output we can see that computation is not waiting.

The tasks are running concurrently.
Think "no-wait" for asynchronous computation. It is also referred to as "non-blocking".

It is a subset of the broader concurrent computation.

Note also that asynchronous computing is not the same as multi-threading.


asynchronous = no-wait

Quick Definitions


From the experiments we can infer these definitions.

Synchronous = wait
Think "wait" for synchronous computation. It is also referred to as "blocking".

When "task1" is called, the computation sits and waits for it to finish before moving to "task2".
Asynchronous = no-wait
Think "no-wait" for asynchronous computation. It is also referred to as "non-blocking".

When "task1" is called, the computation does not wait for it to finish. It immediately moves on to "task2".


Note that synchronous is a type of the broader "sequential", and asynchronous is a type of broader "concurrent" computation.

References