Skip to content

Commit

Permalink
Ptree worker refactors
Browse files Browse the repository at this point in the history
Store next_time locally in the main() function, and in the selftest, run
the main() function for longer than a single tick.
  • Loading branch information
wingo committed Dec 11, 2017
1 parent d49eb7d commit 356d34e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/lib/ptree/worker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ function new_worker (conf)
ret.period = 1/conf.Hz
ret.duration = conf.duration or 1/0
ret.no_report = conf.no_report
ret.next_time = engine.now()
ret.channel = channel.create('config-worker-channel', 1e6)
ret.alarms_channel = alarm_codec.get_channel()
ret.pending_actions = {}
Expand Down Expand Up @@ -94,10 +93,11 @@ end

function Worker:main ()
local stop = engine.now() + self.duration
local next_time = engine.now()
repeat
self.breathe()
if self.next_time < engine.now() then
self.next_time = engine.now() + self.period
if next_time < engine.now() then
next_time = engine.now() + self.period
self:handle_actions_from_manager()
timer.run()
end
Expand All @@ -113,6 +113,6 @@ end

function selftest ()
print('selftest: lib.ptree.worker')
main({duration=0.0001})
main({duration=0.005})
print('selftest: ok')
end

0 comments on commit 356d34e

Please sign in to comment.