lib/metacosm/simulation.rb in metacosm-0.2.0 vs lib/metacosm/simulation.rb in metacosm-0.2.1

- old
+ new

@@ -4,38 +4,43 @@ def watch(model) Frappuccino::Stream.new(model).on_value(&method(:receive)) end def fire(command) + # p [ :firing, command: command ] command_queue.push(command) end def command_queue @command_queue ||= Queue.new end def conduct! - @running = true @conductor_thread = Thread.new { execute } end def execute - while @running + while true if (command=command_queue.pop) - # p [ :applying!, command: command ] apply(command) end sleep 0.01 end end def halt! - @running = false @conductor_thread.terminate end + def mutex + @mutex = Mutex.new + end + def apply(command) + #mutex.synchronize do + # p [ :applying, command: command ] handler_for(command).handle(command.attrs) + #end end def receive(event, record: true) events.push(event) if record