Class: Ztimer::Slot

Inherits:
Object
  • Object
show all
Defined in:
lib/ztimer/slot.rb

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.



7
8
9
10
11
12
13
14
15
# File 'lib/ztimer/slot.rb', line 7

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.



4
5
6
# File 'lib/ztimer/slot.rb', line 4

def callback
  @callback
end

#enqueued_atObject (readonly)

Returns the value of attribute enqueued_at.



4
5
6
# File 'lib/ztimer/slot.rb', line 4

def enqueued_at
  @enqueued_at
end

#executed_atObject

Returns the value of attribute executed_at.



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

def executed_at
  @executed_at
end

#expires_atObject (readonly)

Returns the value of attribute expires_at.



4
5
6
# File 'lib/ztimer/slot.rb', line 4

def expires_at
  @expires_at
end

#recurrencyObject (readonly)

Returns the value of attribute recurrency.



4
5
6
# File 'lib/ztimer/slot.rb', line 4

def recurrency
  @recurrency
end

#started_atObject

Returns the value of attribute started_at.



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

def started_at
  @started_at
end

Instance Method Details

#<=>(other) ⇒ Object



35
36
37
# File 'lib/ztimer/slot.rb', line 35

def <=>(other)
  return @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?
  return @canceled
end

#recurrent?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/ztimer/slot.rb', line 17

def recurrent?
  return @recurrency > 0
end

#reset!Object



21
22
23
24
25
# File 'lib/ztimer/slot.rb', line 21

def reset!
  if recurrent?
    @expires_at += recurrency
  end
end