lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Thu, May 10, 2012 at 10:23 AM, Rob Hoelz <> wrote:
> I'll probably expose the low-level coroutine stuff at some level for
> advanced users/users that wish to extend the library.

Coroutines can make event-based programming 'natural' but you do need
to avoid blocking like the plague.

So if a person wishes to actually do some heavy computation, they need
to understand that they must let the system do some work, with a
sleep(0) or something similar. (this is something that early Windows
programmers needed to know, before truly preemptive threading)

Anything that does I/O can block, particularly sockets, but also when
launching a new process. Copas does that nicely for sockets, (but
using timeout tricks), and there has to be a non-blocking equivalent
of popen. in the absence of true threading, that is the best workhorse
for doing time-consuming calculations.

So, if the API is available, and people learn not to just use standard
I/O and os.popen, then things do work smoothly.

The alternative is very nasty-looking, even without error checking:

open(addr, function(socket)

steve d.