Class: OpenHAB::Core::Timer

Inherits:
Object
  • Object
show all
Defined in:
lib/openhab/core/timer.rb

Overview

Timer allows you to administer the block of code that has been scheduled to run later with after.

Direct Known Subclasses

RSpec::Mocks::Timer

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#execution_timeZonedDateTime? (readonly)

Returns the scheduled execution time, or ‘nil` if the timer was cancelled.

Returns:

  • (ZonedDateTime, nil)

    the scheduled execution time, or ‘nil` if the timer was cancelled



# File 'lib/openhab/core/timer.rb', line 70

#idObject?

Returns:

  • (Object, nil)


34
35
36
# File 'lib/openhab/core/timer.rb', line 34

def id
  @id
end

Instance Method Details

#active?true, false

Check if the timer will execute in the future.

Returns:

  • (true, false)


# File 'lib/openhab/core/timer.rb', line 14

#canceltrue, false

Cancel timer

Returns:

  • (true, false)

    True if cancel was successful, false otherwise



108
109
110
111
# File 'lib/openhab/core/timer.rb', line 108

def cancel
  DSL.timers.delete(self)
  cancel!
end

#cancelled?true, false

Check if the timer has been cancelled.

Returns:

  • (true, false)


# File 'lib/openhab/core/timer.rb', line 18

#inspectString Also known as: to_s

Returns:

  • (String)


58
59
60
61
62
63
64
65
66
67
# File 'lib/openhab/core/timer.rb', line 58

def inspect
  r = "#<#{self.class.name} #{"#{id.inspect} " if id}#{block.source_location.join(":")}"
  if cancelled?
    r += " (cancelled)"
  else
    r += " @ #{execution_time}"
    r += " (executed)" if terminated?
  end
  "#{r}>"
end

#reschedule(time = nil) ⇒ self

Reschedule timer.

If the timer had been cancelled or executed, restart the timer.

Parameters:

  • time (java.time.temporal.TemporalAmount, ZonedDateTime, Proc, nil) (defaults to: nil)

    When to reschedule the timer for. If unspecified, the original time is used.

Returns:

  • (self)


83
84
85
86
87
88
89
90
91
92
# File 'lib/openhab/core/timer.rb', line 83

def reschedule(time = nil)
  return reschedule!(time) unless id

  # re-add ourself to the TimerManager's @timers_by_id
  DSL.timers.schedule(id) do |old_timer|
    old_timer&.cancel unless old_timer.eql?(self)
    self.id = nil
    reschedule!(time)
  end
end

#running?true, false

Check if the timer code is currently running.

Returns:

  • (true, false)


# File 'lib/openhab/core/timer.rb', line 22

#terminated?true, false

Check if the timer has terminated.

Returns:

  • (true, false)


30
# File 'lib/openhab/core/timer.rb', line 30

def_delegator :@timer, :has_terminated, :terminated?