lua-users home
lua-l archive

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


It was thus said that the Great John Belmonte once stated:
> I've posted part 2 of the series:
> 
>   https://gist.github.com/belm0/abbe9acb832eafa10dcbfd2b26eb74fc

  Cool series of articles.  Thanks.

> Notably, it's demonstrating error tracebacks that span multiple coroutines,
> and the ability to catch an error from any intermediate coroutine along the
> way-- just as you would with a call stack that didn't spawn coroutines.

  Some comments on the current implementation:

1. In your _time() function, you can probably get away with:

	local function _time()
	  return os.time() * 1000
	end

If you are relying upon GNU coreutils date command, then you are probably on
a POSIX system, and POSIX systems return the number of seconds from Jan 1,
1970.  No reason to shell out there.

2. For your _schedule_task() routine, you might want to look into binary
heaps.  It's what I use for handing timeouts in my framework dealing with
network events.  You can see the implementation I use at:

	https://github.com/spc476/lua-conmanorg/blob/master/lua/nfl.lua#L63

The two functions are TOQUEUE:insert() and TOQUEUE:remove().  The next task
to run is always in TOQUEUE[1].  You can see me checking this:

	https://github.com/spc476/lua-conmanorg/blob/master/lua/nfl.lua#L166

  I can see why this would be useful, but I would have to think about how I
would add this to my existing framework.  

  -spc