asynchronous vs synchronous
xxxxxxxxxx
Synchronous tasks happen in order—you must complete the current task before moving on to the next.
Asynchronous tasks are executed in any order or even at once.
xxxxxxxxxx
synchronous (sync) - you can only execute one thing at a time
asynchronous (async) - you can execute multiple things at the same time
xxxxxxxxxx
Asynchronous:
In Asynchronous, will not wait to finish first task or response,
it will jump to another my by before finish, once the task get finish
simply it will report.
Asynchronous handle more then one task one at a time (Asynchronous work with 2 hands at a time).
Ajax is best example here.
Synchronous:
In Synchronous, will not take task until finish first.
"No, I'm waiting right here until you finish." This is synchronous.
Synchronous handle task one at a time (Synchronous work with 1 hand at a time).
==========================
// Example 1 - Synchronous will blocks the task
var result = database.query("SELECT * FROM employee");
console.log("Query finished");
console.log("Next line");
// Example 2 - Asynchronous doesn't block the task
database.query("SELECT * FROM employee", function(result) {
console.log("Query finished");
});
console.log("Next line");
xxxxxxxxxx
Asynchronous is a non-blocking architecture, so the execution of one task isn't dependent on another. Tasks can run simultaneously. Synchronous is a blocking architecture, so the execution of each operation depends on completing the one before it.
xxxxxxxxxx
Encryption can be synchronous or asynchronous. Synchronous cryptography is mostly used for data at rest, and also for digital signature. Asynchronous cryptography is usually used for data in transit and in cases where encryption and decryption keys need to be shared or exchanged.