Class: Tuile::FakeEventQueue::FakeTicker

Inherits:
Object
  • Object
show all
Defined in:
lib/tuile/fake_event_queue.rb

Overview

Handle returned by #tick. Mirrors the public surface of EventQueue::Ticker (‘cancel`, `cancelled?`) but does not auto-fire —the host Tuile::FakeEventQueue drives firing via #tick_once.

Instance Method Summary collapse

Constructor Details

#initialize(block) ⇒ FakeTicker

Returns a new instance of FakeTicker.

Parameters:

  • block (Proc)

    called as ‘block.call(tick_count)` on each #fire.



70
71
72
73
74
# File 'lib/tuile/fake_event_queue.rb', line 70

def initialize(block)
  @block = block
  @tick = 0
  @cancelled = false
end

Instance Method Details

#cancelvoid

This method returns an undefined value.

Marks the ticker cancelled. Idempotent. Subsequent #fire calls are no-ops; Tuile::FakeEventQueue#tick_once also prunes the ticker on its next pass.



83
84
85
# File 'lib/tuile/fake_event_queue.rb', line 83

def cancel
  @cancelled = true
end

#cancelled?Boolean

Returns true once #cancel has been called.

Returns:

  • (Boolean)

    true once #cancel has been called.



77
# File 'lib/tuile/fake_event_queue.rb', line 77

def cancelled? = @cancelled

#firevoid

This method returns an undefined value.

Invokes the user block with the current tick counter, then advances. No-op when #cancelled?. Typically driven by Tuile::FakeEventQueue#tick_once; safe to call directly from a test that wants to drive a single ticker.



92
93
94
95
96
97
# File 'lib/tuile/fake_event_queue.rb', line 92

def fire
  return if @cancelled

  @block.call(@tick)
  @tick += 1
end