Skip to content

Instantly share code, notes, and snippets.

@SebastianEdwards
Created August 16, 2011 10:11
Show Gist options
  • Save SebastianEdwards/1148778 to your computer and use it in GitHub Desktop.
Save SebastianEdwards/1148778 to your computer and use it in GitHub Desktop.
unique id issue
class System
createResponseSocket: ->
@responseSocket = zmq.createSocket 'rep'
@responseSocket.bind 'ipc:///tmp/system-master', (err) =>
if err
throw err
@responseSocket.on 'message', (data) =>
@handleMessage data, (response) =>
@responseSocket.send(response)
handleMessage: (msg, callback) ->
msg = msg.toString('utf8')
recipient = parseInt(msg.slice(0,3))
if recipient == 999
data = BISON.decode(msg.slice(3))
switch data.type
# Snip
when 'NEW-ID'
@getNewID (id) ->
callback id.toString()
# Snip
getNewID: (callback) ->
console.log @idCounter
callback ++@idCounter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment