DEV Community

[Comment from a deleted post]
Collapse
 
zenntenn profile image
zenntenn

In C# using await like in the "bad" example is the correct pattern, as it's not designed at all for parallelism. Also, your weird example will produce the exact same effect in C#.

If this is just a JavaScript example you should make that clear, although I thought browser JavaScript code is still all single threaded, but I don't do much in the way of JavaScript so maybe I'm wrong though. Either way I think you at least need to clarify a few things.

Collapse
 
wforney profile image
Bill Forney

C# has Task.WhenAll(taskArray) for this...

Collapse
 
peq profile image
Peter Zeller

The purpose of async/await is parallelism (in the form of cooperative multitasking), so if you don't use it, just use a plain old fashioned function instead of an async function.

If you are always calling your async function with await before it, you're getting none of the benefits of async.