Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.openwrt.org/project/libubox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/uloop-example.lua17
1 files changed, 17 insertions, 0 deletions
diff --git a/examples/uloop-example.lua b/examples/uloop-example.lua
index 511b9ea..f3aef60 100755
--- a/examples/uloop-example.lua
+++ b/examples/uloop-example.lua
@@ -24,6 +24,23 @@ uloop.timer(function() print("2000 ms timer run"); end, 2000)
-- timer example 3 (will never run)
uloop.timer(function() print("3000 ms timer run"); end, 3000):cancel()
+-- periodic interval timer
+local intv
+intv = uloop.interval(function()
+ print(string.format("Interval expiration #%d - %dms until next expiration",
+ intv:expirations(), intv:remaining()))
+
+ -- after 5 expirations, lower interval to 500ms
+ if intv:expirations() >= 5 then
+ intv:set(500)
+ end
+
+ -- cancel after 10 expirations
+ if intv:expirations() >= 10 then
+ intv:cancel()
+ end
+end, 1000)
+
-- process
function p1(r)
print("Process 1 completed")