Skip to content

Commit

Permalink
timer_task: add schedule_one()
Browse files Browse the repository at this point in the history
  • Loading branch information
davidor committed Jul 2, 2018
1 parent 693328b commit c238af4
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions gateway/src/resty/concurrent/timer_task.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ function _M:execute(run_now)
run_periodic(run_now or false, self.id, self.task, self.args, self.interval)
end

--- Schedule one task.
function _M:schedule_one(delay)
-- Need to wrap the task in a function that discards the first param (the
-- "premature" one sent by ngx.timer.at)
ngx.timer.at(delay or 0, function(_, ...) self.task(...) end, unpack(self.args))
end

function _M:cancel()
_M.unregister_task(self.id)
end
Expand Down

0 comments on commit c238af4

Please sign in to comment.