]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: hlua: core.wait() takes optional delay paramater
authorAurelien DARRAGON <adarragon@haproxy.com>
Tue, 1 Apr 2025 13:22:29 +0000 (15:22 +0200)
committerAurelien DARRAGON <adarragon@haproxy.com>
Thu, 3 Apr 2025 15:52:28 +0000 (17:52 +0200)
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.

doc/lua-api/index.rst
src/hlua.c

index 267b9f42f859089d3f2a532093683b9868a6adea..4231e32e15f79237bc49307a6629383df8715f40 100644 (file)
@@ -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()
 
index ac253361b0c43e4b0f1db4bb102f03e01e28fdfe..2e7c93bfb0b8e5e329b2a4861b43580dcbaa3b3e 100644 (file)
@@ -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;
 }