Class: Tuile::FakeEventQueue
- Inherits:
-
Object
- Object
- Tuile::FakeEventQueue
- Defined in:
- lib/tuile/fake_event_queue.rb
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 Method Summary collapse
- #await_empty ⇒ void
-
#initialize ⇒ FakeEventQueue
constructor
A new instance of FakeEventQueue.
- #locked? ⇒ Boolean
- #post(event) ⇒ void
- #run_loop ⇒ void
- #stop ⇒ void
- #submit { ... } ⇒ void
-
#tick(fps) {|tick| ... } ⇒ FakeTicker
Mirrors EventQueue#tick but timeless: returns a FakeTicker that only fires when a test calls #tick_once.
-
#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 Method Details
#await_empty ⇒ void
This method returns an undefined value.
22 |
# File 'lib/tuile/fake_event_queue.rb', line 22 def await_empty; end |
#locked? ⇒ Boolean
12 13 |
# File 'lib/tuile/fake_event_queue.rb', line 12 def locked? = true # @return [void] |
#post(event) ⇒ void
This method returns an undefined value.
33 |
# File 'lib/tuile/fake_event_queue.rb', line 33 def post(event); end |
#run_loop ⇒ void
This method returns an undefined value.
17 18 19 |
# File 'lib/tuile/fake_event_queue.rb', line 17 def run_loop raise Tuile::Error, "FakeEventQueue does not run an event loop" end |
#stop ⇒ void
This method returns an undefined value.
14 |
# File 'lib/tuile/fake_event_queue.rb', line 14 def stop; end |
#submit { ... } ⇒ void
This method returns an undefined value.
27 28 29 |
# File 'lib/tuile/fake_event_queue.rb', line 27 def submit yield end |
#tick(fps) {|tick| ... } ⇒ FakeTicker
Mirrors EventQueue#tick but timeless: returns a FakeTicker that only fires when a test calls #tick_once. The ‘fps` 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.
46 47 48 49 50 51 52 53 |
# File 'lib/tuile/fake_event_queue.rb', line 46 def tick(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 FakeTicker.new(block).tap { |t| @tickers << t } 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.
60 61 62 63 |
# File 'lib/tuile/fake_event_queue.rb', line 60 def tick_once @tickers.reject!(&:cancelled?) @tickers.each(&:fire) end |