lua-users home
lua-l archive

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


Lightroom uses a coroutine system that allows yielding from anywhere (well, modulo pcall limitations).[*] Mostly this works well, but there have been times where bugs have come up because the state of the world changed out from under some code that didn't think about the fact that the operation being invoked — even though it was clearly a long running operation — could yield.

Revel doesn't use coroutines. It's approach could be described as a mixture of node.js with Flapjax where the reactive model allows us to avoid drowning the control flow in explicit callbacks. That said, I have been thinking about adding some support for coroutines in order to make it easier to write "try A, if that fails, try B" and such like.

Mark

On May 10, 2012, at 6:03 PM, Tim Caswell <tim@creationix.com> 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.

On the other hand, lua developers have more experience with coroutines than js developers, so I may be way off in my concerns.  As always I love to see people experimenting!

On Thu, May 10, 2012 at 3:56 PM, Jorge <xxopxe@gmail.com> wrote:
On mié, 2012-05-09 at 07:22 -0400, Rob Hoelz wrote:
> Basically, I want to create an event library for Lua that sits on top
> of another event library (luaevent for now, but I would probably make
> the system flexible enough for a different library should that be
> desired).

For completeness sake: https://github.com/xopxe/Lumen

It does not depend on a event library, but on a library that provides a
select or poll-like call. At the moment, luasocket and nixio are
supported. It's of the "cooperative, events&blocking, coroutine based,
calculating the timeout for a select" class.

The API looks like this:

---------------------------------------------------
local sched = require "sched"

local emitter_task=sched.run(function()
       sched.catalog.register('A')
       while true do
               sched.signal('ev', 'data!')
               sched.sleep(5)
       end
end)

sched.run(function()
       local waitd={emitter=emitter_task, events={'ev'}}
       while true do
               _, m = sched.wait(waitd)
               print (m)
       end
end)

sched.go()
---------------------------------------------------

Good luck in your quest :)

Jorge