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



134
135
136
137
138
# File 'lib/joyce.rb', line 134

def kickstart!
  server = new
  server.boot
  server
end

Instance Method Details

#bootObject



94
95
96
97
98
99
100
101
# File 'lib/joyce.rb', line 94

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



111
112
113
114
115
116
117
118
119
# File 'lib/joyce.rb', line 111

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

#halt!Object



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

def halt!
  @driving = false
end

#joinObject



103
104
105
# File 'lib/joyce.rb', line 103

def join
  @cmd_thread.join
end

#received_commandsObject



129
130
131
# File 'lib/joyce.rb', line 129

def received_commands
  sim.received_commands
end

#setupObject



90
91
92
# File 'lib/joyce.rb', line 90

def setup
  # p [ :server_setup ]
end

#simObject



125
126
127
# File 'lib/joyce.rb', line 125

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

#tickObject



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

def tick
  # p [ :server_tick ]
end