mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Optimized the scheduler
This commit is contained in:
@@ -18,6 +18,7 @@ SCHEDULER = {
|
||||
|
||||
--- SCHEDULER constructor.
|
||||
-- @param #SCHEDULER self
|
||||
-- @param #table TimeEventObject
|
||||
-- @param #function TimeEventFunction
|
||||
-- @param #table TimeEventFunctionArguments
|
||||
-- @param #number StartSeconds
|
||||
@@ -49,13 +50,12 @@ function SCHEDULER:New( TimeEventObject, TimeEventFunction, TimeEventFunctionArg
|
||||
if StopSeconds then
|
||||
self.StopSeconds = StopSeconds
|
||||
end
|
||||
|
||||
self.Repeat = false
|
||||
|
||||
self.StartTime = timer.getTime()
|
||||
|
||||
self:T("Calling function " .. timer.getTime() + self.StartSeconds )
|
||||
|
||||
timer.scheduleFunction( self.Scheduler, self, timer.getTime() + self.StartSeconds + .01 )
|
||||
|
||||
self:Start()
|
||||
|
||||
return self
|
||||
end
|
||||
@@ -81,7 +81,7 @@ function SCHEDULER:Scheduler()
|
||||
self:T( { Status, Result } )
|
||||
|
||||
if Status and Status == true and Result and Result == true then
|
||||
if not self.StopSeconds or ( self.StopSeconds and timer.getTime() <= self.StartTime + self.StopSeconds ) then
|
||||
if self.Repeat and ( not self.StopSeconds or ( self.StopSeconds and timer.getTime() <= self.StartTime + self.StopSeconds ) ) then
|
||||
timer.scheduleFunction(
|
||||
self.Scheduler,
|
||||
self,
|
||||
@@ -92,6 +92,21 @@ function SCHEDULER:Scheduler()
|
||||
|
||||
end
|
||||
|
||||
function SCHEDULER:Start()
|
||||
self:F( self.TimeEventObject )
|
||||
|
||||
self.Repeat = true
|
||||
timer.scheduleFunction( self.Scheduler, self, timer.getTime() + self.StartSeconds + .01 )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function SCHEDULER:Stop()
|
||||
self:F( self.TimeEventObject )
|
||||
|
||||
self.Repeat = false
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user