]> jfr.im git - irc/quakenet/newserv.git/blob - lua/lib/scheduler.lua
CHANSERV: better batcher error handling for expired accounts/accounts with no email.
[irc/quakenet/newserv.git] / lua / lib / scheduler.lua
1 Scheduler = class(function(obj)
2 obj.sched = raw_scheduler_new()
3 end)
4
5 function Scheduler:add(when, callback, ...)
6 return self:add_abs(os.time() + when, callback, ...)
7 end
8
9 function Scheduler:add_abs(w, callback, ...)
10 local args = { ... }
11 local pfn = function()
12 callback(unpack(args))
13 end
14
15 return raw_scheduler_add(self.sched, w, function()
16 local status, err = pcall(pfn)
17 if not status then
18 scripterror(err)
19 end
20 end)
21 end
22
23 function Scheduler:remove(tag)
24 raw_scheduler_remove(tag)
25 end
26
27 function Scheduler:getn()
28 return raw_scheduler_count(self.sched)
29 end