Skip to content

Instantly share code, notes, and snippets.

@pilif
Created February 27, 2012 19:13
Show Gist options
  • Save pilif/1926402 to your computer and use it in GitHub Desktop.
Save pilif/1926402 to your computer and use it in GitHub Desktop.
redis = require 'redis'
spawn = require('child_process').spawn
waiter = (i)->
console.log "waiter #{i} connecting"
c = redis.createClient 6379, 'localhost'
c.on "connect", ->
c.select 2, (err, res) ->
popper(c, i)
c.on "error", ->
c.quit()
true
popper = (redis, i) ->
console.log "popper #{i} about to be popping"
redis.blpop 'channel:gnegg', 0, (err, res) ->
return console.error "popper encountered error #{err}" if err
console.log "popper #{i} has popped and would shell out"
response = '';
cat = spawn '/bin/cat'
cat.stdin.write "hi, dear cat! Here is some data.\n"
cat.stdin.write "and here's the redis result: #{res}\n"
cat.stdin.end();
cat.stdout.on 'data', (d) ->
response += d
cat.on 'exit', (code) ->
console.log "popper subprocess has finished. Exitcode: #{code}"
console.log "popper-content: #{response}"
process.nextTick ->
popper(redis, i)
for i in [0..4]
waiter(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment