DEV Community

Panda Quests
Panda Quests

Posted on

Are "asynchronous" and "parallel" the same terms in software development?

Top comments (2)

Collapse
 
pizmovc profile image
Luka • Edited

Parallel means there are multiple different things happening at the same time. You can listen to music and cook at the same time. You're doing these two things in parallel.

Asynchronous is used when you start some process, that you know will finish at some point, but you're not going to wait for it. Sending an email is asynchronous communication, because you send an email and you know that you'll get a reply some time in the future. Having a phone call is synchronous communication, since you have to wait for the other person to stop talking, so that you can talk and vice-versa.

You can combine the two. If you sent an email to several recipients, they can all be writing their replies at the same time (in parallel). But you'd still be waiting for their replies (while possibly doing other things).

An example asynchronous task is fetching some resource (some text lets say). You fire the request, then when it is finished some task happens (Promise/Callback).

console.log(1);
get('https://cdn.com/someImage').then((image) => { displayImageSize(image) });
console.log(2);

The above example would print

1
2
1232kb

An example for parallel task is processing something in the background, like calculating something that will that a long time).

const possiblePrimes = [3, 5, 1233112, 568543, 6575323445];
console.log(1);
possiblePrimes.foreach((number) => {
  // Creates a background task and starts it in 0 ms (meaning right now)
  setTimeout(() => console.log(isPrime(number)), 0);
};
console.log(2);

The above example would print 1 then 2 and them some sequence of true/false. Since the isPrime will be running in parallel the fastest result will be printed first (probably true for 3).

Collapse
 
sduduzog profile image
Sdu

Nope. I'll try to explain this how I understand it so I won't be providing textbook level descriptions

Parallel probably refers to entities like processes running side by side, like imagine how a browser could be playing a yutube video but when you scroll down the thing fetches comments all at the same time. There's like so many other things going on in that one page and those processes are happening in parallel.

Asynchronous or synhronous most likely describes how tasks are carried out or how messages are handled for instance,

var name = prompt("What is your name");
console.log("the name is", name);

We could describe the above line of code as synchronous code. Copy and paste it to your browser console. You'll notice that the name is not printed out until you've done some action to the prompt dialog. The following instruction will never be acted upon if the first one has not finished. An opposite to this is Asynchronous which one example I can make is you writting this post and continuing to live your life. After some time, I wrote this silly comment to respond and the sole purpose of this post has been fulfilled. No matter how long it took, it didn't stop you from closing the browser and going on about your day.

Sorry this is a mess, I could have made a better example to explain this but I just took a couple of minutes while I am at work