Merge pull request #10 from Shoozza/patch-1

This commit is contained in:
Enrique García Cota 2022-01-20 23:37:55 +01:00 committed by GitHub
commit bedcb48355
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -31,32 +31,34 @@ Changes the internal timer manually to `running`, or to 0 if nothing is specifie
Examples Examples
======== ========
local cron = require 'cron' ```lua
local cron = require 'cron'
local function printMessage() local function printMessage()
print('Hello') print('Hello')
end end
-- the following calls are equivalent: -- the following calls are equivalent:
local c1 = cron.after(5, printMessage) local c1 = cron.after(5, printMessage)
local c2 = cron.after(5, print, 'Hello') local c2 = cron.after(5, print, 'Hello')
c1:update(2) -- will print nothing, the action is not done yet c1:update(2) -- will print nothing, the action is not done yet
c1:update(5) -- will print 'Hello' once c1:update(5) -- will print 'Hello' once
c1:reset() -- reset the counter to 0 c1:reset() -- reset the counter to 0
-- prints 'hey' 5 times and then prints 'hello' -- prints 'hey' 5 times and then prints 'hello'
while not c1:update(1) do while not c1:update(1) do
print('hey') print('hey')
end end
-- Create a periodical clock: -- Create a periodical clock:
local c3 = cron.every(10, printMessage) local c3 = cron.every(10, printMessage)
c3:update(5) -- nothing (total time: 5) c3:update(5) -- nothing (total time: 5)
c3:update(4) -- nothing (total time: 9) c3:update(4) -- nothing (total time: 9)
c3:update(12) -- prints 'Hello' twice (total time is now 21) c3:update(12) -- prints 'Hello' twice (total time is now 21)
```
Gotchas / Warnings Gotchas / Warnings
================== ==================
@ -72,7 +74,9 @@ Just copy the cron.lua file somewhere in your projects (maybe inside a /lib/ fol
Remember to store the value returned by require somewhere! (I suggest a local variable named `cron`) Remember to store the value returned by require somewhere! (I suggest a local variable named `cron`)
local cron = require 'cron' ```lua
local cron = require 'cron'
```
Also, make sure to read the license file; the text of that license file must appear somewhere in your projects' files. Also, make sure to read the license file; the text of that license file must appear somewhere in your projects' files.
@ -81,7 +85,9 @@ Specs
This project uses [busted](https://olivinelabs.com/busted) for its specs. If you want to run the specs, you will have to install it first. Then run: This project uses [busted](https://olivinelabs.com/busted) for its specs. If you want to run the specs, you will have to install it first. Then run:
cd path/where/the/spec/folder/is ```bash
busted cd path/where/the/spec/folder/is
busted
```