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 'eventmachine' | |
require 'em-websocket' | |
class CustomWSConnection < EventMachine::WebSocket::Connection | |
def trigger_on_message(msg) | |
send "Pong: #{msg}" | |
end | |
def trigger_on_open | |
send "Hello Client!" |
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 'em-hiredis' | |
EM.run { | |
redis = EM::Hiredis.connect | |
redis.set('foo', 'value') | |
redis.watch('foo') { | |
puts "Watching - try changing key foo within 1s" | |
EM.add_timer(1) { |
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 'em-hiredis' | |
EM.run { | |
require 'em-hiredis' | |
redis = EM::Hiredis.connect | |
# If you pass a block to subscribe it will be called whenever a message | |
# is received on this channel | |
redis.pubsub.subscribe('foo') { |msg| | |
p [:received_foo, msg] |
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 :rubygems | |
gem 'em-websocket' | |
gem 'sinatra' |
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-hiredis' | |
require 'fiber' | |
class Cache | |
include EM::Deferrable | |
def initialize(key) | |
$redis.get(key) { |v| | |
@value = v |
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 'em-hiredis' | |
class EM::Hiredis::Client | |
class Transaction | |
include EM::Deferrable | |
def initialize(redis) | |
@redis = redis | |
end | |
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' | |
# Allows calling set/clear at will, and ensures that only a single on_set or | |
# on_clear deferrable is running concurrently. It also ensures that | |
# un-necessary callbacks are not run, i.e. set-unset-set in sequency only | |
# requires the on_set callback to run once | |
# | |
# The blocks/procs supplied for on_set and on_clear must return deferrables | |
# | |
class Thing |
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 :rubygems | |
gem 'eventmachine', '1.0.0.rc.4' | |
gem 'em-http-request', '1.0.2' | |
gem 'sinatra' | |
gem 'thin' |
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
.bundle | |
bundle | |
vendor |
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
<html> | |
<head> | |
<script> | |
function debug(string) { | |
var element = document.getElementById("debug"); | |
var p = document.createElement("p"); | |
p.appendChild(document.createTextNode(string)); | |
element.appendChild(p); | |
} |