Class: Ztimer::Slot

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#callbackObject (readonly)

Returns the value of attribute callback.



6
7
8
# File 'lib/ztimer/slot.rb', line 6

def callback
  @callback
end

#enqueued_atObject (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_atObject

Returns the value of attribute executed_at.



7
8
9
# File 'lib/ztimer/slot.rb', line 7

def executed_at
  @executed_at
end

#expires_atObject (readonly)

Returns the value of attribute expires_at.



6
7
8
# File 'lib/ztimer/slot.rb', line 6

def expires_at
  @expires_at
end

#recurrencyObject (readonly)

Returns the value of attribute recurrency.



6
7
8
# File 'lib/ztimer/slot.rb', line 6

def recurrency
  @recurrency
end

#started_atObject

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

Returns:

  • (Boolean)


27
28
29
# File 'lib/ztimer/slot.rb', line 27

def canceled?
  @canceled
end

#recurrent?Boolean

Returns:

  • (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