Last active
January 2, 2016 01:49
-
-
Save jamescarr/8233282 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| zmq = require 'zmq' | |
| address = 'inproc://foobar' | |
| class Cycle | |
| constructor: (@items) -> | |
| next: -> | |
| @items.push(item = @items.shift()) | |
| return item | |
| channelA = zmq.socket 'router' | |
| channelA.identity = 'channel-A' | |
| channelA.on 'message', (envelope, message) -> | |
| console.log "#{envelope} sent back #{message}" | |
| channelB = zmq.socket 'router' | |
| channelB.identity = 'channel-B' | |
| channelB.on 'message', (envelope, number) -> | |
| channelB.send [envelope, parseInt(number) + parseInt(number)] | |
| channelC = zmq.socket 'router' | |
| channelC.identity = 'channel-C' | |
| channelC.on 'message', (envelope, number) -> | |
| channelC.send [envelope, number * number] | |
| cycle = new Cycle(['channel-B', 'channel-C']) | |
| channelA.bind address, -> | |
| channelC.connect address | |
| channelB.connect address | |
| num = 10; | |
| setInterval(-> | |
| env = cycle.next() | |
| console.log "sending #{num} to #{env}" | |
| channelA.send [env, num++] | |
| , 2000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment