-
-
Save lachie/65150813829df97f5d70 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
source "https://rubygems.org" | |
gem "celluloid" | |
gem "pusher" |
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 'rubygems' | |
require 'bundler/setup' | |
require 'celluloid' | |
require 'pusher' | |
ENV['PUSHER_URL'] || abort("hey, set PUSHER_URL") | |
$outstanding_requests = {} | |
class Messenger | |
include Celluloid | |
def send_msg(id) | |
$outstanding_requests[id] = true | |
pusher_client.trigger("private-ch-#{id}", "update", {id: id}) | |
$outstanding_requests.delete id | |
end | |
def pusher_client | |
@pusher_client ||= Pusher::Client.new({}).tap {|c| | |
# work around the way url is set for clients | |
c.url = ENV['PUSHER_URL'] | |
} | |
end | |
end | |
messenger = Messenger.pool | |
100.times do |id| | |
messenger.async.send_msg(id) | |
end | |
loop do | |
print "outstanding requests:" | |
p $outstanding_requests | |
sleep 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment