3 ms·
It is a more principled replacement for the get_context, set_context pair. And more powerful vecause it is run inside the to coroutine, so the coroutine that ca
by gpderetta 6y ago
It is a more principled replacement for the get_context, set_context pair. And more powerful vecause it is run inside the to coroutine, so the coroutine that called swap is already suspended.
Things you can do from the closure:
- delete the 'from' coroutine
- return into the 'to' coroutine a different coroutine than 'from' (or even bo coroutine at all). This is useful to implement blocking primitives amd schedulers.
- throw an exception into the to coroutine (for example for exception forwarding or even just to force the target coroutine to exit)
And much more of course.
It is a very powerful primitive analogous to call-with-current-continuation.
- artemonster 6y agoThanks for the explanation!