Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentes Révision précédente
scheduler [01.11.2017 17:45]
Steven Piccand
scheduler [01.11.2017 18:16] (Version actuelle)
Steven Piccand
Ligne 169: Ligne 169:
 </​file>​ </​file>​
  
-Version minifiée+Version ​[[https://​mothereff.in/​lua-minifier|minifiée]]
 <code lua> <code lua>
 Scheduler={events={},​started=false,​getSleepDuration=function(self,​time)return(time-t)*1000 end,​insert=function(self,​a)local b=false;​local c=1;while not b and c<​=#​self.events do if self.events[c].runAt>​a.runAt then table.insert(self.events,​c,​a)b=true end;c=c+1 end;if not b then self.events[#​self.events+1]=a end;​table.sort(self.events,​function(d,​e)return d.runAt<​e.runAt end)end,​add=function(self,​a)if type(a.time)=="​string"​then local f=os.date("​*t"​)local g,​h=string.match(time,"​(%d+):​(%d+)"​)a.runAt=os.time{year=f.year,​month=f.month,​day=f.day,​hour=g,​min=h,​sec=0}if a.runAt<​os.time()then a.runAt=os.time{year=f.year,​month=f.month,​day=f.day+1,​hour=g,​min=h,​sec=0}end elseif not a.runAt then a.runAt=os.time()+a.time end;​self:​insert(a)end,​run=function(self)while self.started do if#​self.events>​0 then local a=self.events[1]fibaro:​sleep(self:​getSleepDuration(a.runAt))if self.started then a.func()if a.auto then self:​add({time=a.time,​func=a.func,​auto=a.auto})end;​table.remove(self.events,​1)end end end end,​start=function(self)if not Scheduler.started then self.started=true;​self:​run()end end,​stop=function(self)self.started=false end,​clear=function(self)self.events={}end} Scheduler={events={},​started=false,​getSleepDuration=function(self,​time)return(time-t)*1000 end,​insert=function(self,​a)local b=false;​local c=1;while not b and c<​=#​self.events do if self.events[c].runAt>​a.runAt then table.insert(self.events,​c,​a)b=true end;c=c+1 end;if not b then self.events[#​self.events+1]=a end;​table.sort(self.events,​function(d,​e)return d.runAt<​e.runAt end)end,​add=function(self,​a)if type(a.time)=="​string"​then local f=os.date("​*t"​)local g,​h=string.match(time,"​(%d+):​(%d+)"​)a.runAt=os.time{year=f.year,​month=f.month,​day=f.day,​hour=g,​min=h,​sec=0}if a.runAt<​os.time()then a.runAt=os.time{year=f.year,​month=f.month,​day=f.day+1,​hour=g,​min=h,​sec=0}end elseif not a.runAt then a.runAt=os.time()+a.time end;​self:​insert(a)end,​run=function(self)while self.started do if#​self.events>​0 then local a=self.events[1]fibaro:​sleep(self:​getSleepDuration(a.runAt))if self.started then a.func()if a.auto then self:​add({time=a.time,​func=a.func,​auto=a.auto})end;​table.remove(self.events,​1)end end end end,​start=function(self)if not Scheduler.started then self.started=true;​self:​run()end end,​stop=function(self)self.started=false end,​clear=function(self)self.events={}end}
 </​code>​ </​code>​