-
-
Save vangberg/472285 to your computer and use it in GitHub Desktop.
This file contains 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
var sys = require('sys'); | |
var http = require('http'); | |
var host = '127.0.0.1'; | |
var couch = http.createClient(5984, host); | |
var listen = function() { | |
sys.log("listening"); | |
var request = couch.request('GET', '/demo/_changes?feed=continuous', {'host': host}); | |
request.end(); | |
request.addListener('response', function (response) { | |
if (response.statusCode == 200) { | |
response.setEncoding('utf8'); | |
response.addListener('data', function (chunk) { | |
sys.log(chunk); | |
}); | |
response.addListener('end', listen); | |
} else { | |
setTimeout(listen, 5000); | |
} | |
}); | |
}; | |
listen(); |
This file contains 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
require "eventmachine" | |
require "em-http" | |
class CouchListen | |
def initialize database | |
@database = database | |
@feed_url = "http://127.0.0.1:5984/#{database}/_changes?feed=continuous" | |
end | |
def listen | |
http = EventMachine::HttpRequest.new(@feed_url).get :timeout => 0 | |
http.stream {|chunk| print(".") } | |
http.errback { EM.add_timer(5) {listen} } | |
end | |
end | |
EventMachine.run { CouchListen.new("memolane").listen } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment