Skip to content

Instantly share code, notes, and snippets.

@rudyjahchan
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rudyjahchan/9276835 to your computer and use it in GitHub Desktop.
Save rudyjahchan/9276835 to your computer and use it in GitHub Desktop.
createGameProcess = (attributes, server)->
gameProcess = child_process.fork "#{__dirname}/game_process"
gameProcess.on 'message', server.onGameProcessMessage
gameProcess.send type: 'init', game: attributes
gameProcess
class Server
constructor: (attributes={})->
@games = {}
getGame: (attributes) ->
attributes.name ?= Moniker.choose()
@games[attributes.name] = (@games[attributes.name] ? createGameProcess(attributes, @))
onGameProcessMessage: (message)=>
switch message.type
when 'game'
@onGameChange(message.game)
when 'stopped'
@onGameStopped(message.name)
when 'cycleAdded'
@onCycleAdded(message)
when 'addCycleFailed'
@onAddCycleFailed(message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment