Time-related functions for Lua, inspired in javascript's setTimeout and setInterval
Go to file
2011-04-24 17:15:54 +02:00
spec cancel is also working, with tests 2011-04-24 17:06:35 +02:00
BSD-LICENSE.txt did not make the initial commit correctly. Oh, well. On this commit update, reset and after are implemented and passing tests. Only every is missing 2011-04-24 16:15:44 +02:00
cron.lua small update refactoring 2011-04-24 17:15:54 +02:00
README.textile update README 2011-04-24 17:08:22 +02:00

h1. cron.lua

@cron.lua@ are a set of functions for executing actions at a certain time interval.

h1. Examples of use

* @cron.after(time, callback)@ will execute callback after the given amount of time units. Returns an identifier (@id@)
* @cron.every(time, callback)@ will repeat the same action periodically. Returns an identifier (@id@)
* @cron.cancel(id)@ will stop a timed event from happening. It will stop a timed event from happening, or stop a periodic action.
* @cron.reset()@ removes all timed and periodic actions, and resets the time passed back to 0.
* @cron.update(dt)@ is needed to be executed on the main program loop. @dt@ is the amount of time that has passed since the last iteration. When @cron.update@ is executed, cron will check the list of pending actions and execute them if needed.


h1. Gotchas / Warnings

* @cron.lua@ does *not* implement any hardware or software clock; you will have to provide it with the access to the hardware timers, in the form of periodic calls to @cron.update@
* @cron@ does not have any defined time units (seconds, milliseconds, etc). You define the units it uses by passing it a @dt@ on @cron.update@. If @dt@ is in seconds, then @cron@ will work in seconds. If @dt@ is in milliseconds, then @cron@ will work in milliseconds.

h1. Installation

Just copy the cron.lua file somewhere in your projects (maybe inside a /lib/ folder) and require it accordingly.

Remember to store the value returned by require somewhere! (I suggest a local variable named @cron@)

<pre>
local cron = require 'cron'
</pre>

Also, make sure to read the license file; the text of that license file must appear somewhere in your projects' files.

h1. Specs

This project uses "telescope":https://github.com/norman/telescope for its specs. If you want to run the specs, you will have to install telescope first. Then just enter the spec folder and execute run.lua:

<pre>
cd path/to/cron.lua/specs
lua run.lua
</pre>