3 ms·
I suppose the „fn“ executed in „to“ context before return is executed to do some clean-up or de-allocations for caller? I.e. to make a proper „return“ possible?
by artemonster 6y ago
I suppose the „fn“ executed in „to“ context before return is executed to do some clean-up or de-allocations for caller? I.e. to make a proper „return“ possible? Could you explain this maybe in more detail? And which closure is passed?
- gpderetta 6y agoIt 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!