[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Options for Asynchronous Callbacks
- From: steve donovan <steve.j.donovan@...>
- Date: Wed, 28 Mar 2012 13:56:01 +0200
On Wed, Mar 28, 2012 at 1:37 PM, Axel Kittenberger <axkibe@gmail.com> wrote:
> The more you work with immutables, the easier it gets.
True, but using Lua we are restricted, and luvit is a similar kind of
solution to the single-threaded issue as Node.js is for JavaScript.
I must say that _coroutines_ make writing async-style code so much
more pleasant. For instance, in this snippet that sets up a Windows
named pipe server:
winapi.make_pipe_server_async(function(f)
while true do
local res = f:read()
if res == 'close' then break end
f:write(res:upper())
end
print 'finis'
end)
the file object f is wrapped (a la Copas) so that it is not actually
blocking on reads. Getting the write to be non-blocking continues to
be an interesting exercise...
Similar tricks are possible for making waiting-on-processes coroutine-friendly.
steve d.