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.

Filter by
Sorted by
Tagged with
7 votes
1 answer
418 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 ...
25 votes
3 answers
3k 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 ...
20 votes
5 answers
5k 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 ...
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 ...
5 votes
1 answer
149 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 ...
12 votes
1 answer
400 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 ...