Difference between revisions of "cron"

(Created page with "{{#set:Name=cron}} {{#set:LOVE Version=Any}} {{#set:Description=A set of functions for executing actions at a certain time interval.}} A set of functions for executing actions at...")
 
m (Adding keyword.)
Line 2: Line 2:
 
{{#set:LOVE Version=Any}}
 
{{#set:LOVE Version=Any}}
 
{{#set:Description=A set of functions for executing actions at a certain time interval.}}
 
{{#set:Description=A set of functions for executing actions at a certain time interval.}}
 +
{{#set:Keyword=Timer}}
 
A set of functions for executing actions at a certain time interval by Enrique García Cota aka [https://github.com/kikito kikito].
 
A set of functions for executing actions at a certain time interval by Enrique García Cota aka [https://github.com/kikito kikito].
  

Revision as of 11:37, 18 January 2017



A set of functions for executing actions at a certain time interval by Enrique García Cota aka kikito.

Download

local cron = require 'cron'

local function printMessage()
  print('Hello')
end

-- the following calls are equivalent:
local c1 = cron.after(5, printMessage)
local c2 = cron.after(5, print, 'Hello')

c1:update(2) -- will print nothing, the action is not done yet
c1:update(5) -- will print 'Hello' once

c1:reset() -- reset the counter to 0

-- prints 'hey' 5 times and then prints 'hello'
while not c1:update(1) do
  print('hey')
end

-- Create a periodical clock:
local c3 = cron.every(10, printMessage)

c3:update(5) -- nothing (total time: 5)
c3:update(4) -- nothing (total time: 9)
c3:update(12) -- prints 'Hello' twice (total time is now 21)


Links