Module: Ruck::ObjectConvenienceMethods

Defined in:
lib/ruck/shreduler.rb

Instance Method Summary collapse

Instance Method Details

#raise_event(event) ⇒ Object

raises an event on the default EventClock of the global Shreduler.



145
146
147
# File 'lib/ruck/shreduler.rb', line 145

def raise_event(event)
  $shreduler.event_clock.raise_all(event)
end

#spork(&block) ⇒ Object

creates a new Shred with the given block on the global Shreduler



119
120
121
# File 'lib/ruck/shreduler.rb', line 119

def spork(&block)
  $shreduler.shredule(Shred.new(&block))
end

#spork_loop(delay_or_event = nil, clock = nil, &block) ⇒ Object

creates a new Shred with the given block on the global Shreduler, automatically surrounded by loop { }. If the delay_or_event parameter is given, a Shred.yield(delay) or Shred.wait_on(event) is inserted before the call to your block.



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/ruck/shreduler.rb', line 127

def spork_loop(delay_or_event = nil, clock = nil, &block)
  shred = Shred.new do
    while Shred.current.running?
      if delay_or_event
        if delay_or_event.is_a?(Numeric)
          Shred.yield(delay_or_event, clock)
        else
          Shred.wait_on(delay_or_event)
        end
      end
      
      block.call
    end
  end
  $shreduler.shredule(shred)
end