MINOR: hlua: core.wait() takes optional delay paramater
core.wait() now accepts optional delay parameter in ms. Passed this delay the task is woken up if no event woke the task before. Lua documentation was updated.
This commit is contained in:
parent
1e4e5ab4d2
commit
c7cbfafa38
@ -926,13 +926,17 @@ Core class
|
||||
its work and wants to give back the control to HAProxy without executing the
|
||||
remaining code. It can be seen as a multi-level "return".
|
||||
|
||||
.. js:function:: core.wait()
|
||||
.. js:function:: core.wait([milliseconds])
|
||||
|
||||
**context**: task, action
|
||||
|
||||
Give back the hand at the HAProxy scheduler. Unlike :js:func:`core.yield`
|
||||
the task will not be woken up automatically to resume as fast as possible.
|
||||
Instead, it will wait for an event to wake the task.
|
||||
Instead, it will wait for an event to wake the task. If milliseconds argument
|
||||
is provided then the Lua excecution will be automatically resumed passed this
|
||||
delay even if no event caused the task to wake itself up.
|
||||
|
||||
:param integer milliseconds: automatic wakeup passed this delay. (optional)
|
||||
|
||||
.. js:function:: core.yield()
|
||||
|
||||
|
15
src/hlua.c
15
src/hlua.c
@ -9251,10 +9251,23 @@ __LJMP static int hlua_yield(lua_State *L)
|
||||
* automatically woken up to resume ASAP, instead it means we will wait for
|
||||
* an event to occur to wake the task. Only use when you're confident that
|
||||
* something or someone will wake the task at some point.
|
||||
*
|
||||
* Takes optional <delay> argument as parameter, in which case an automatic
|
||||
* wake will be performed after <delay>
|
||||
*/
|
||||
__LJMP static int hlua_wait(lua_State *L)
|
||||
{
|
||||
MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_yield_yield, TICK_ETERNITY, 0));
|
||||
int nb_arg;
|
||||
unsigned int delay;
|
||||
int wakeup_ms = TICK_ETERNITY; // tick value
|
||||
|
||||
nb_arg = lua_gettop(L);
|
||||
if (nb_arg >= 1) {
|
||||
delay = MAY_LJMP(luaL_checkinteger(L, 1));
|
||||
wakeup_ms = tick_add(now_ms, delay);
|
||||
}
|
||||
|
||||
MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_yield_yield, wakeup_ms, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user