https://github.com/makefu/timed-loop
A timed Loop for nodemcu
https://github.com/makefu/timed-loop
Last synced: 11 months ago
JSON representation
A timed Loop for nodemcu
- Host: GitHub
- URL: https://github.com/makefu/timed-loop
- Owner: makefu
- License: wtfpl
- Created: 2015-04-03T21:44:37.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-04-03T23:15:23.000Z (about 11 years ago)
- Last Synced: 2024-12-27T16:30:23.980Z (over 1 year ago)
- Language: Lua
- Size: 97.7 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: COPYING
Awesome Lists containing this project
README
# Introduction
This module implements 'timed' loops with the pattern ``function(i) -> sleep(delay) ->function(i+1)``.
This project is in works-for-me status.
# Usage
> -- new timed loop with timer-id 3
> l = require('loop').new(3)
> function derp(i)
> print("derp: "..i.." id: "..l:get_tmr_id())
> end
> function yay(i)
> print("finished yay! "..i)
> end
> -- start the loop, count from 1 to 10, increment 1, delay of 1000ms
> l:loop(1,10,1,1000,derp)
> -- use another timer,change the timer id of the current timer
> tmr.alarm(4,2000,function () l:set_tmr_id(4) end )
> -- register 'end' callback
> l:on_finished(yay)
> -- stop timer after 3.5 seconds,
> -- end callback will be executed with the last counter
> tmr.alarm(5,3500,function () l:stop() end )
> -- Output:
derp: 1 id: 3
derp: 2 id: 3
derp: 3 id: 3
derp: 4 id: 4
derp: 5 id: 4
finished yay! 5