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()
* 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;
}