lib/ztimer/slot.rb in ztimer-0.3.2 vs lib/ztimer/slot.rb in ztimer-0.4.0
- old
+ new
@@ -1,17 +1,28 @@
module Ztimer
class Slot
- attr_reader :enqueued_at, :expires_at, :callback
+ attr_reader :enqueued_at, :expires_at, :recurrency, :callback
attr_accessor :started_at, :executed_at
- def initialize(enqueued_at, expires_at, &callback)
+ def initialize(enqueued_at, expires_at,recurrency = -1, &callback)
@enqueued_at = enqueued_at
@expires_at = expires_at
+ @recurrency = recurrency
@callback = callback
@started_at = nil
@executed_at = nil
@canceled = false
+ end
+
+ def recurrent?
+ return @recurrency > 0
+ end
+
+ def reset!
+ if recurrent?
+ @expires_at += recurrency
+ end
end
def canceled?
return @canceled
end
\ No newline at end of file