Class: Ztimer::Slot
- Inherits:
-
Object
- Object
- Ztimer::Slot
- Defined in:
- lib/ztimer/slot.rb
Overview
Implements a slot, which represents a block of code to be executed at specified time slot.
Instance Attribute Summary collapse
-
#callback ⇒ Object
readonly
Returns the value of attribute callback.
-
#enqueued_at ⇒ Object
readonly
Returns the value of attribute enqueued_at.
-
#executed_at ⇒ Object
Returns the value of attribute executed_at.
-
#expires_at ⇒ Object
readonly
Returns the value of attribute expires_at.
-
#recurrency ⇒ Object
readonly
Returns the value of attribute recurrency.
-
#started_at ⇒ Object
Returns the value of attribute started_at.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #cancel! ⇒ Object
- #canceled? ⇒ Boolean
-
#initialize(enqueued_at, expires_at, recurrency = -1,, &callback) ⇒ Slot
constructor
A new instance of Slot.
- #recurrent? ⇒ Boolean
- #reset! ⇒ Object
Constructor Details
#initialize(enqueued_at, expires_at, recurrency = -1,, &callback) ⇒ Slot
Returns a new instance of Slot.
9 10 11 12 13 14 15 16 17 |
# File 'lib/ztimer/slot.rb', line 9 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 |
Instance Attribute Details
#callback ⇒ Object (readonly)
Returns the value of attribute callback.
6 7 8 |
# File 'lib/ztimer/slot.rb', line 6 def callback @callback end |
#enqueued_at ⇒ Object (readonly)
Returns the value of attribute enqueued_at.
6 7 8 |
# File 'lib/ztimer/slot.rb', line 6 def enqueued_at @enqueued_at end |
#executed_at ⇒ Object
Returns the value of attribute executed_at.
7 8 9 |
# File 'lib/ztimer/slot.rb', line 7 def executed_at @executed_at end |
#expires_at ⇒ Object (readonly)
Returns the value of attribute expires_at.
6 7 8 |
# File 'lib/ztimer/slot.rb', line 6 def expires_at @expires_at end |
#recurrency ⇒ Object (readonly)
Returns the value of attribute recurrency.
6 7 8 |
# File 'lib/ztimer/slot.rb', line 6 def recurrency @recurrency end |
#started_at ⇒ Object
Returns the value of attribute started_at.
7 8 9 |
# File 'lib/ztimer/slot.rb', line 7 def started_at @started_at end |
Instance Method Details
#<=>(other) ⇒ Object
35 36 37 |
# File 'lib/ztimer/slot.rb', line 35 def <=>(other) @expires_at <=> other.expires_at end |
#cancel! ⇒ Object
31 32 33 |
# File 'lib/ztimer/slot.rb', line 31 def cancel! @canceled = true end |
#canceled? ⇒ Boolean
27 28 29 |
# File 'lib/ztimer/slot.rb', line 27 def canceled? @canceled end |
#recurrent? ⇒ Boolean
19 20 21 |
# File 'lib/ztimer/slot.rb', line 19 def recurrent? @recurrency.positive? end |
#reset! ⇒ Object
23 24 25 |
# File 'lib/ztimer/slot.rb', line 23 def reset! @expires_at += recurrency if recurrent? end |