[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua coroutines to async/await feature
- From: Russell Haley <russ.haley@...>
- Date: Tue, 22 Nov 2016 18:12:16 -0800
On Tue, Nov 22, 2016 at 4:59 PM, Dibyendu Majumdar
<mobile@majumdar.org.uk> wrote:
> Hi
>
> This is just something I have been wondering about. I personally have
> not yet found a use case for Lua's coroutines - the main reason being
> that the resume has to be explicit. What would be more useful is if
> the coroutine semantics could be harnessed to create an async/await
> type solution as in C#. That is, can a solution be found to
> automatically resume the coroutine when an event associated with a
> 'yield' completes. As Lua is single threaded so the solution needs to
> resume the coroutine within the same OS thread.
>
> I haven't really tried solving this but I thought it might be a useful
> enhancement to Lua if a solution could be found. I imagine that a
> background OS thread will be needed to monitor completion of events
> and then some coordination with the VM will be necessary to resume
> suspended coroutines, maybe whenever the VM does an operation that
> requires system resources.
Something like this?
http://25thandclement.com/~william/projects/cqueues.html
Very slick stuff. Also see
https://github.com/daurnimator/lua-http
and my shameless plug:
https://github.com/RussellHaley/lua-http-endpoints
Russ
> In some ways the 'go' language works like
> this - i.e. there is a background scheduler that swaps in suspended
> goroutines to the thread whenever execution would otherwise pause.
>
> This is just me thinking aloud, so please feel free to shoot it down,
> or point me to existing solutions that achieve this (I imagine
> projects that integrate libuv might be doing this already).
>
> Thanks and Regards
> Dibyendu
>