[HN Gopher] Philosophy of Coroutines
___________________________________________________________________
Philosophy of Coroutines
Author : Tomte
Score : 58 points
Date : 2023-09-01 18:17 UTC (4 hours ago)
(HTM) web link (www.chiark.greenend.org.uk)
(TXT) w3m dump (www.chiark.greenend.org.uk)
| krylon wrote:
| Lua makes coroutines first class citizens. I have only built one
| toy project with it, but it was very enjoyable. Someone even
| managed to implement Erlang-style concurrency on top of Lua's
| coroutines. That was a lot of fun to play with. (/stares into the
| night, reminiscing/)
| max_k wrote:
| If you like Lua coroutines and C++20 coroutines, I have written
| a piece of code that allows to combine both:
| https://github.com/CM4all/libcommon/blob/master/src/lua/CoAw...
|
| It's used for example by our "myproxy" project:
| https://github.com/CM4all/myproxy/blob/master/src/Connection...
| (Ctrl-F Lua::CoAwaitable) - a Lua coroutine is launched from
| within a C++20 coroutine and the C++20 coroutine awaits the Lua
| coroutine. Everything integrated in a non-blocking I/O event
| loop.
| vacuity wrote:
| Coroutines really are powerful. Here's to hoping Rust stabilizes
| generators (full semicoroutines, not the enhanced iteration
| construct) sooner rather than later. It would give programmers
| greater control to express state machine logic without being
| boxed into async/await. I do wonder if the `Context` parameter
| used for async tasks is appropriate for arbitrary generators, so
| if someone could chime in on this I would be grateful.
| mratsim wrote:
| Or provide continuations and use them to implement coroutines.
| qudat wrote:
| A couple of us have been experimenting with deliminited
| continuations and I think it's gonna take off soon in TS
|
| https://youtu.be/uRbqLGj_6mI?si=kgKKjpCnehJ9bpIG
|
| https://github.com/neurosnap/starfx
| https://github.com/thefrontside/effection/tree/v3
| vacuity wrote:
| To my understanding, delimited continuations and coroutines
| are equivalent in power. Out of curiosity, can delimited
| continuations be implemented as efficiently (in Rust or
| otherwise) as stackless coroutines?
| pflanze wrote:
| I've been using genawaiter[1] for writing generators in Rust.
| Are there things you can't build on top of async-await? Or is
| it just that it's simpler without that indirection?
|
| [1]: https://crates.io/crates/genawaiter
| vacuity wrote:
| I was thinking that the semantics around async/await
| (function coloring) would make some usages more frustrating.
| This crate probably sidesteps that, if it is a problem at
| all. I have a bad habit of not dabbling around when I lack
| understanding.
___________________________________________________________________
(page generated 2023-09-01 23:00 UTC)