lua-users home
lua-l archive

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

On 11 May 2012 02:03, Tim Caswell <> wrote:
> My only warning with making the non-blocking operations appear blocking is
> that it will bite novice programmers big time.  Any function call into a
> third-party library will have the potential to suspend your current
> coroutine.  Part of the reason I created luvit was to see what node.js would
> be like if the language has proper coroutines.  Luvit supports them, but I
> still much prefer callbacks because it makes the points where other stuff
> can happen explicit.  With implicit suspensions you get into nasty
> issues similar to thread preemption where local state changes out from under
> you because some other event messed with your data.  Node did add coroutines
> to javascript early on for this very reason, but it was soon removed because
> it bit too many people way too often.  Both experiences and novice
> developers were constantly bit by it.

Indeed. I've reached the point where I like to use coroutines
sparingly. Prosody's code is callback based, though we use coroutines
in places where the code gets complex. If you've ever written
callback-heavy code, you understand the kind of places that a
coroutine approach would make more sense for. Similarly if you've ever
written coroutine-heavy code, you understand the pitfalls there too -
the high-level code is simpler, but runtime issues get a lot harder to
debug, and the low-level code driving the coroutines is rarely

On the topic of event libraries, I think it's pretty clear from this
thread alone that people are prone to just roll their own. It's not
/hard/, most of the base libraries already have high-level APIs (from
LuaEvent to Luvit at the extreme). Everyone has their own requirements
and preferences for an API that will ultimately be at the very heart
of their application.

We've long pondered formally releasing Prosody's. Ultimately I don't
have the motivation - it doesn't seem like there is a great need for
yet another event library, and it would take time and effort to spin
the project off and maintain it. Nevertheless, I personally use it in
just about every networked Lua app I develop.