Skip to main content

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.

9 votes
1 answer
301 views

How to compile to preemptive coroutines?

I am interested in the concept of stackful coroutines, as how it is used by the developer in a language. I have learned that Erlang and Go (perhaps some other languages) does have preemptive ...
Jonas's user avatar
  • 705
8 votes
1 answer
550 views

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
20 votes
5 answers
6k views

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
  • 301
16 votes
5 answers
5k views

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
  • 3,458
6 votes
1 answer
202 views

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
  • 3,458
13 votes
1 answer
676 views

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
  • 15.3k
26 votes
3 answers
5k views

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