Class: Tuile::FakeEventQueue::FakeTicker

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

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

@param block — called as block.call(tick_count) on each #fire.

Parameters:

  • block (Proc)


86
87
88
89
90
# File 'lib/tuile/fake_event_queue.rb', line 86

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.



99
100
101
# File 'lib/tuile/fake_event_queue.rb', line 99

def cancel
  @cancelled = true
end

#cancelled?Boolean

@return — true once #cancel has been called.

Returns:

  • (Boolean)


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

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.



108
109
110
111
112
113
# File 'lib/tuile/fake_event_queue.rb', line 108

def fire
  return if @cancelled

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