From bbada260d7689eb1a0b4cb5570937b1895646d15 Mon Sep 17 00:00:00 2001 From: Ryan Ward Date: Tue, 5 Nov 2024 13:00:49 -0500 Subject: [PATCH] updated changes and added multi.isTimeout function --- docs/changes.md | 33 ++++++++++++++++++++++++++++++++- init.lua | 7 +++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/docs/changes.md b/docs/changes.md index 2b2a6d6..9aebff6 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -1,7 +1,8 @@ # Changelog Table of contents --- -[Update 16.0.1 - Bug fix](#update-1531---bug-fix)
+[Update 16.1.0 - TBA](#update-1610---tba)
+[Update 16.0.1 - Bug fix](#update-1601---bug-fix)
[Update 16.0.0 - Connecting the dots](#update-1600---getting-the-priorities-straight)
[Update 15.3.1 - Bug fix](#update-1531---bug-fix)
[Update 15.3.0 - A world of connections](#update-1530---a-world-of-connections)
@@ -59,6 +60,36 @@ Table of contents [Update: EventManager 1.0.0 - Error checking](#update-eventmanager-100---error-checking)
[Version: EventManager 0.0.1 - In The Beginning things were very different](#version-eventmanager-001---in-the-beginning-things-were-very-different) +# Update 16.1.0 - TBA +Added +--- +- `multi.isTimeout(res)` returns true if the response it gets is a timeout type or a string equal to `multi.TIMEOUT`'s value +- `multi:newTimeout(seconds)` returns a connection that will trigger after a certain amount of time. See example below: +```lua +local multi, thread = require("multi"):init() + +data = multi:newConnection() + +-- This alarm takes too long... We will timeout +multi:newAlarm(4):OnRing(function() + sitedata:Fire({Type="request"},"data is tasty") +end) + +multi:newThread(function() + res, data = thread.hold(data + multi:newTimeout(3)) + if multi.isTimeout(res) then + print("We timed out!") + else + print("We got the data:", data) + end + os.exit() +end) + +multi:mainloop() +``` + +If the alarm takes longer the the timeout: `We timed out!` If the alarm is shorter: `We got the data: data is tasty` + # Update 16.0.1 - Bug fix Fixed --- diff --git a/init.lua b/init.lua index bfc616f..ed62e9a 100644 --- a/init.lua +++ b/init.lua @@ -2234,6 +2234,13 @@ end -- UTILS -------- +function multi.isTimeout(res) + if type(res) == "table" then + return res.Type == multi.TIMEOUT + end + return res == multi.TIMEOUT +end + function table.merge(t1, t2) for k,v in pairs(t2) do if type(v) == 'table' then