Module: Scarpe::CatsCradle

Defined in:
lib/scarpe/cats_cradle.rb

Overview

"Cat's Cradle" is a children's game where they interlace string between their fingers to make beautiful complicated shapes. The interlacing of fibers made it a good name for a prototype.

An attempt at an experimental Fiber-based control-flow system to deal with Shoes, Display and JS all at the same time.

In general, we'll use Fiber.transfer to bounce control back and forth between the evented implementations (e.g. waiting for redraw) that need to return control to Webview, and the procedural test flows that look far better if we don't do that explicitly.

Ruby Fiber basic docs: https://ruby-doc.org/core-3.0.0/Fiber.html

This module is mixed into an object to coordinate fibers app-wide.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cc_instanceObject (readonly)

Returns the value of attribute cc_instance.



207
208
209
# File 'lib/scarpe/cats_cradle.rb', line 207

def cc_instance
  @cc_instance
end

Instance Method Details

#event_initObject



209
210
211
212
# File 'lib/scarpe/cats_cradle.rb', line 209

def event_init
  @cc_instance ||= CCInstance.instance
  @cc_instance.event_init
end

#on_every_heartbeat(&block) ⇒ Object



218
219
220
# File 'lib/scarpe/cats_cradle.rb', line 218

def on_every_heartbeat(&block)
  @cc_instance.on_event(:every_heartbeat, &block)
end

#on_heartbeat(&block) ⇒ Object



214
215
216
# File 'lib/scarpe/cats_cradle.rb', line 214

def on_heartbeat(&block)
  @cc_instance.on_event(:next_heartbeat, &block)
end

#on_init(&block) ⇒ Object



222
223
224
# File 'lib/scarpe/cats_cradle.rb', line 222

def on_init(&block)
  @cc_instance.on_event(:init, &block)
end

#on_next_redraw(&block) ⇒ Object



226
227
228
# File 'lib/scarpe/cats_cradle.rb', line 226

def on_next_redraw(&block)
  @cc_instance.on_event(:next_redraw, &block)
end