Class: Musa::Clock::DummyClock

Inherits:
Clock
  • Object
show all
Defined in:
lib/musa-dsl/transport/dummy-clock.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Clock

#on_change_position, #on_start, #on_stop, #running?

Constructor Details

#initialize(ticks = nil, do_log: nil, &block) ⇒ DummyClock

Returns a new instance of DummyClock.

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
15
16
# File 'lib/musa-dsl/transport/dummy-clock.rb', line 6

def initialize(ticks = nil, do_log: nil, &block)
  do_log ||= false

  super()

  raise ArgumentError, 'Cannot initialize with ticks and block. You can only use one of the parameters.' if ticks && block

  @ticks = ticks
  @do_log = do_log
  @block = block
end

Instance Attribute Details

#blockObject

Returns the value of attribute block.



18
19
20
# File 'lib/musa-dsl/transport/dummy-clock.rb', line 18

def block
  @block
end

#ticksObject

Returns the value of attribute ticks.



18
19
20
# File 'lib/musa-dsl/transport/dummy-clock.rb', line 18

def ticks
  @ticks
end

Instance Method Details

#runObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/musa-dsl/transport/dummy-clock.rb', line 20

def run
  @on_start.each(&:call)
  @run = true

  while @run && eval_condition
    yield if block_given?

    Thread.pass
  end

  @on_stop.each(&:call)
end

#terminateObject



33
34
35
# File 'lib/musa-dsl/transport/dummy-clock.rb', line 33

def terminate
  @run = false
end