Questions tagged [coroutines]

For questions about design and implementation of coroutines, a generalization of subroutines that can be paused and resumed. Indicate in the question whether the coroutines are symmetric or asymmetric, stackful or stackless, and first-class or not.

Filter by
Sorted by
Tagged with
7 votes
1 answer

How are coroutines implemented in a tree-walking interpreter?

It seems to me that coroutines and derived abstractions like the iterators and generators are implemented the following way: When returning Move the function's stack frame to the heap Save a pointer ...
Matheus Moreira's user avatar
16 votes
5 answers

Why do so few languages have this type of coroutine feature?

I used to code a lot in a language called Supercollider, which is a domain-specific language for sound synthesis and computer music. One really nice feature it has is coroutines. Python also has these ...
N. Virgo's user avatar
  • 261
15 votes
5 answers

Why can many languages' futures not be canceled?

I noticed that many languages' built-in asynchronous Future cannot be canceled once called. Although many third-party libraries provide this ability, it is not ...
Aster's user avatar
  • 2,626
5 votes
1 answer

How continuations compiles generators and coroutines?

Motivation I have seen many places saying that CPST (continuation-passing style transformation) can express all control flows, but the examples they give are relatively simple and do not involve any ...
Aster's user avatar
  • 2,626
12 votes
1 answer

How do I implement coroutines on WebAssembly?

I am building a compiler targeting WebAssembly for a language that makes heavy use of first-class coroutines. WASM doesn't have native coroutine support (yet), so I have to emulate it. Given the ...
Michael Homer's user avatar
  • 11.7k
23 votes
3 answers

What are the benefits of stackful vs. stackless coroutines?

Many languages that use async nowadays are implemented via stackless coroutines. That is, in a language like Python or Javascript, when you ...
Silvio Mayolo's user avatar