Class: Tuile::FakeEventQueue
- Inherits:
-
Object
- Object
- Tuile::FakeEventQueue
- Defined in:
- lib/tuile/fake_event_queue.rb,
sig/tuile.rbs
Overview
A "synchronous" event queue – no loop is run, submitted blocks are run right away and submitted events are thrown away. Intended for testing only.
Defined Under Namespace
Classes: FakeTicker
Instance Attribute Summary collapse
-
#tickers ⇒ ::Array[FakeTicker]
readonly
Lets a spec assert that a component started a ticker, and — via FakeTicker#cancelled? — that it cancelled one rather than merely dropping it.
Instance Method Summary collapse
- #await_empty ⇒ void
-
#initialize ⇒ FakeEventQueue
constructor
A new instance of FakeEventQueue.
-
#on_loop_thread? ⇒ Boolean
@return — always true.
-
#post(event) ⇒ void
@param
event. - #run_loop ⇒ void
-
#running? ⇒ Boolean
@return — always false — #run_loop raises, so no loop ever runs.
- #stop ⇒ void
- #submit { ... } ⇒ void
-
#tick(seconds, &block) ⇒ void
Mirrors EventQueue#tick but timeless: returns a FakeTicker that only fires when a test calls #tick_once.
-
#tick_fps(fps, &block) ⇒ void
Mirrors EventQueue#tick_fps: validates
fpsfor parity, then delegates to #tick (the fake discards the interval regardless). -
#tick_once ⇒ void
Test helper: fires every live ticker's user block once and prunes cancelled tickers.
Constructor Details
#initialize ⇒ FakeEventQueue
Returns a new instance of FakeEventQueue.
7 8 9 |
# File 'lib/tuile/fake_event_queue.rb', line 7 def initialize @tickers = [] end |
Instance Attribute Details
#tickers ⇒ ::Array[FakeTicker] (readonly)
Lets a spec assert that a component started a ticker, and — via Tuile::FakeEventQueue::FakeTicker#cancelled? — that it cancelled one rather than merely dropping it. Cancelled tickers stay here until the next #tick_once prunes them.
@return — the registered tickers, in creation order.
16 17 18 |
# File 'lib/tuile/fake_event_queue.rb', line 16 def tickers @tickers end |
Instance Method Details
#await_empty ⇒ void
This method returns an undefined value.
31 |
# File 'lib/tuile/fake_event_queue.rb', line 31 def await_empty; end |
#on_loop_thread? ⇒ Boolean
@return — always true.
21 22 |
# File 'lib/tuile/fake_event_queue.rb', line 21 def on_loop_thread? = true # @return [void] |
#post(event) ⇒ void
This method returns an undefined value.
@param event
42 |
# File 'lib/tuile/fake_event_queue.rb', line 42 def post(event); end |
#run_loop ⇒ void
This method returns an undefined value.
26 27 28 |
# File 'lib/tuile/fake_event_queue.rb', line 26 def run_loop raise Tuile::Error, "FakeEventQueue does not run an event loop" end |
#running? ⇒ Boolean
@return — always false — #run_loop raises, so no loop ever runs.
19 20 |
# File 'lib/tuile/fake_event_queue.rb', line 19 def running? = false # @return [Boolean] always true. |
#stop ⇒ void
This method returns an undefined value.
23 |
# File 'lib/tuile/fake_event_queue.rb', line 23 def stop; end |
#submit { ... } ⇒ void
This method returns an undefined value.
36 37 38 |
# File 'lib/tuile/fake_event_queue.rb', line 36 def submit yield end |
#tick(seconds, &block) ⇒ void
This method returns an undefined value.
Mirrors EventQueue#tick but timeless: returns a FakeTicker that
only fires when a test calls #tick_once. The seconds argument is
validated the same way the real queue validates it, then discarded —
the fake has no clock, so frame cadence is up to the test.
@param seconds — interval between firings, must be positive. Validated for parity with EventQueue#tick; otherwise unused.
55 56 57 58 59 60 61 62 |
# File 'lib/tuile/fake_event_queue.rb', line 55 def tick(seconds, &block) raise ArgumentError, "block required" unless block unless seconds.is_a?(Numeric) && seconds.positive? raise ArgumentError, "seconds must be a positive Numeric, got #{seconds.inspect}" end FakeTicker.new(block).tap { |t| @tickers << t } end |
#tick_fps(fps, &block) ⇒ void
This method returns an undefined value.
Mirrors EventQueue#tick_fps: validates fps for parity, then delegates
to #tick (the fake discards the interval regardless).
@param fps — firings per second, must be positive.
71 72 73 74 75 76 77 78 |
# File 'lib/tuile/fake_event_queue.rb', line 71 def tick_fps(fps, &block) raise ArgumentError, "block required" unless block unless fps.is_a?(Numeric) && fps.positive? raise ArgumentError, "fps must be a positive Numeric, got #{fps.inspect}" end tick(1.0 / fps, &block) end |
#tick_once ⇒ void
This method returns an undefined value.
Test helper: fires every live ticker's user block once and prunes cancelled tickers. No-op when no tickers are registered. Pumps once per call regardless of any ticker's fps — the fake has no clock, so tests pump N frames by calling this N times.
85 86 87 88 |
# File 'lib/tuile/fake_event_queue.rb', line 85 def tick_once @tickers.reject!(&:cancelled?) @tickers.each(&:fire) end |