]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/commitdiff
For api_timer_loop() also execute the command immediately.
authorBram Matthys <redacted>
Wed, 26 Apr 2023 18:02:32 +0000 (20:02 +0200)
committerBram Matthys <redacted>
Wed, 26 Apr 2023 18:02:32 +0000 (20:02 +0200)
This so you don't have to wait eg 1000ms for the first update.

api/common_api.php

index 04af80c631df56e10543e61da2ee54fdbf533973..0b0f924e9e691b8167cd99c5a9040737ae2740dd 100644 (file)
@@ -79,6 +79,11 @@ function api_timer_loop(int $every_msec, string $method, array|null $params = nu
 {
        GLOBAL $rpc;
 
+       /* First, execute it immediately */
+       $res = $rpc->query($method, $params);
+       if (!$res)
+               die;
+       send_sse($res);
        $rpc->rpc()->add_timer("timer", $every_msec, $method, $params);
        if ($rpc->error)
        {
@@ -94,6 +99,12 @@ function api_timer_loop(int $every_msec, string $method, array|null $params = nu
        }
 
        /* New style: use server-side timers */
+       /* - First, execute it immediately */
+       $res = $rpc->query($method, $params);
+       if (!$res)
+               die;
+       send_sse($res);
+       /* - Then add the timer */
        for(;;)
        {
                $res = $rpc->eventloop();