Module: lib-tde.function.delayed-timer

This module run a timer periodically, but has an initial delay before running.

Usually people use gears.timer however when starting the desktop environment every timer gets triggered at the same time. This can result in peaks of cpu usage followed by times with no cpu usage. This is fine for small programs, but if a program uses considerable cpu time this can cause "lag". Delayed timer is used to "spread" the execution of async repeating code (for example polling). This is how you use the api:

-- this will print hello every 5 seconds, after an initial delay of 10 seconds
-- It however by default calls the callback function on startup once
lib-tde.function.delayed-timer(5, function()
    print("hello")
end, 10)

-- If you want to do the same as above but without the call when creating the time
lib-tde.function.delayed-timer(5, function()
    print("hello")
end, 10, true)

Info:

  • Copyright: 2020 Tom Meyers
  • Author: Tom Meyers

Static module functions

lib-tde.function.delayed-timer.delayed-timer (timeout, callback, delay[, only_delay]) Async callback trigger, that starts after x seconds


Static module functions

lib-tde.function.delayed-timer.delayed-timer (timeout, callback, delay[, only_delay])
Async callback trigger, that starts after x seconds

Parameters:

  • timeout number How long to wait until we call the callback again
  • callback function The callback function to call when the timeout happened
  • delay number How long to wait until we start the async timer
  • only_delay bool By default we call the callback on creation, when true we don't call the callback (optional)

Usage:

    -- lib-tde.function.delayed-timer(1, function()
         print("Callback")
    end, 10, true)
generated by LDoc 1.4.6 Build with 💜 By F0xedb Last updated 2021-05-21 03:30:15