Class: Joyce::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/joyce.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.kickstart!Object



119
120
121
122
123
# File 'lib/joyce.rb', line 119

def kickstart!
  server = new
  server.boot
  server
end

Instance Method Details

#bootObject



79
80
81
82
83
84
85
86
# File 'lib/joyce.rb', line 79

def boot
  sim.on_event(publish_to: EVENT_STREAM)
  @cmd_thread = sim.subscribe_for_commands(channel: COMMAND_QUEUE)
  setup
  sim.conduct!
  drive!
  # cmd_thread.join
end

#drive!Object



96
97
98
99
100
101
102
103
104
# File 'lib/joyce.rb', line 96

def drive!
  @driving = true
  Thread.new do
    while @driving
      tick
      sleep 0.05
    end
  end
end

#halt!Object



106
107
108
# File 'lib/joyce.rb', line 106

def halt!
  @driving = false
end

#joinObject



88
89
90
# File 'lib/joyce.rb', line 88

def join
  @cmd_thread.join
end

#received_commandsObject



114
115
116
# File 'lib/joyce.rb', line 114

def received_commands
  sim.received_commands
end

#setupObject



75
76
77
# File 'lib/joyce.rb', line 75

def setup
  # p [ :server_setup ]
end

#simObject



110
111
112
# File 'lib/joyce.rb', line 110

def sim
  @simulation ||= Metacosm::Simulation.current
end

#tickObject



92
93
94
# File 'lib/joyce.rb', line 92

def tick
  # p [ :server_tick ]
end