[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: [ANN] Nested coroutines
- From: Richter, Jörg <Joerg.Richter@...>
- Date: Wed, 30 Sep 2015 14:26:45 +0000
> This module provides a thin wrapper around the standard coroutine module
> to allow the definition of complex behaviors with nested coroutines.
I also have created something similar for our use. The interface is a bit different.
It has the notation of "tagged" resume and yield and two new functions
coroutine.resumetag() and coroutine.yieldtag().
Usage is like this:
local tag = {}
coroutine.resumetag( co, tag, args )
...
coroutine.yieldtag( co, tag, args )
The yieldtag() will yield the execution up to the corresponding resumtag() call, skipping
resumetag() calls with different tags.
resume() and yield() are modified to use an anonymous tag for themselves.
This has the benefit that you don't need to modify every library.
You only have to pay attention that no one saves coroutine.yield or resume in a global upvalue,
because they will be replaced.
I think there should be some standard library for this. Because it is not possible to
solve this multi-coroutine-yield when every library uses a different approach.
Your module is a nice start, though.
- Jörg