2
\$\begingroup\$

I just created the tag. However, I then noticed that there is already the tag. I think these are distinct concepts, even though in some languages, that distinction is a bit blurry. I would argue that coroutines are not necessarily asynchronous. However, if the consensus is that they are just synonyms, then perhaps one should be made a synonym of the other (or just removed)?

\$\endgroup\$

1 Answer 1

4
\$\begingroup\$

Coroutines and async/await are not the same.

Coroutines are a control flow mechanism. You can reimplement coroutines by using goto and mutating an address both sides have access to. As such a coroutine is to goto, what for loops are to while loops. A form of sugar.

Async/await requires arbitrary suspension and resumption of functions so builds off of coroutines. As goto would be horrible to work with. However the async/await pattern specializes coroutines with a scheduler to manage the coroutines.

You can build your own async/await scheduler in any language which supports coroutines (not generators, which only support unidirectional communication). Which is how Python had support for the async/await pattern way before async and await were added to the language.


in some languages, that distinction is a bit blurry.

If the only coroutines the language supports are async/await ones then users likely can conflate the two concepts.

coroutines are not necessarily asynchronous

Coroutines have nothing to do with asynchronous. Asynchronous (async/await) requires* coroutines to work.

*: T&C apply

if the consensus is that they are just synonyms, then perhaps one should be made a synonym of the other (or just removed)?

The two terms are not synonymous. As such the tag shouldn't be removed because of such a train of thought.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .