Skip to content

Instantly share code, notes, and snippets.

@lachie

lachie/Gemfile Secret

Last active August 29, 2015 14:17
Show Gist options
  • Save lachie/65150813829df97f5d70 to your computer and use it in GitHub Desktop.
Save lachie/65150813829df97f5d70 to your computer and use it in GitHub Desktop.
source "https://rubygems.org"
gem "celluloid"
gem "pusher"
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