summaryrefslogtreecommitdiff
path: root/indra/llcommon
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2024-05-31 17:15:06 -0400
committerNat Goodspeed <nat@lindenlab.com>2024-05-31 17:15:06 -0400
commitde719553fddc381e274d8bff218ab4e3f6691945 (patch)
treefa43af2d44d8fdb0ea881d6f36fe39e5d6308088 /indra/llcommon
parent894dd1937511df08fa57c5e586d40a7778473dae (diff)
Add timers.lua API module and test_timers.lua test program.
Since timers presents a timers.Timer Lua class supporting queries and cancellation, make TimersListener::scheduleAfter() and scheduleEvery() respond immediately so the newly constructed Timer object has the reqid necessary to perform those subsequent operations. This requires that Lua invocations of these operations avoid calling the caller's callback with that initial response. Reinvent leap.generate() to return a Lua object supporting next() and done() methods. A plain Lua coroutine that (indirectly) calls fiber.wait() confuses the fiber scheduler, so avoid implementing generate() as a Lua coroutine. Add a bit more leap.lua diagnostic output.
Diffstat (limited to 'indra/llcommon')
-rw-r--r--indra/llcommon/llcallbacklist.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/indra/llcommon/llcallbacklist.cpp b/indra/llcommon/llcallbacklist.cpp
index 59ff8d3759..9f324b2fe9 100644
--- a/indra/llcommon/llcallbacklist.cpp
+++ b/indra/llcommon/llcallbacklist.cpp
@@ -410,11 +410,14 @@ private:
void TimersListener::scheduleAfter(const LLSD& params)
{
+ // Timer creation functions respond immediately with the reqid of the
+ // created timer, as well as later when the timer fires. That lets the
+ // requester invoke cancel, isRunning or timeUntilCall.
+ Response response(LLSD(), params);
LLSD::Real after{ params["after"] };
if (after < MINTIMER)
{
- sendReply(llsd::map("error", stringize("after must be at least ", MINTIMER)), params);
- return;
+ return response.error(stringize("after must be at least ", MINTIMER));
}
mHandles.emplace(
@@ -432,11 +435,14 @@ void TimersListener::scheduleAfter(const LLSD& params)
void TimersListener::scheduleEvery(const LLSD& params)
{
+ // Timer creation functions respond immediately with the reqid of the
+ // created timer, as well as later when the timer fires. That lets the
+ // requester invoke cancel, isRunning or timeUntilCall.
+ Response response(LLSD(), params);
LLSD::Real every{ params["every"] };
if (every < MINTIMER)
{
- sendReply(llsd::map("error", stringize("every must be at least ", MINTIMER)), params);
- return;
+ return response.error(stringize("every must be at least ", MINTIMER));
}
mHandles.emplace(