lua-users home
lua-l archive

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


On Tue, Dec 2, 2008 at 5:02 PM,  <esmil@mailme.dk> wrote:
>> On Tuesday 02, esmil@mailme.dk wrote:
>>> This is all very good and works fine except for one situation: Say a
>>> thread is yielded while waiting for data, but in the meantime the
>>> connection is closed or some other error happens and I want to
>>> immediately stop execution of the thread and clean up the data
>>> associated with it. The problem is that now I can't get to the data I
>>> pushed to the stack before starting it, so what I really need is some
>>> way to resume the thread, but throw an error immediately. I've been
>>> looking through the manual several times now, but I can't figure out
>>> how to do that. Am I just blind or is there a good reason this isn't
>>> possible?

Just do it. Resume, and throw an error immediately.

If your yields always exect to get back

  true, arg1, arg2

or

  nil, emsg

whenever the yield returns, it can assert success:

ok, arg1, arg2 = assert(coroutine.yield("read-wait", {fd=4}))

Sam