concurrently to a service handler by one or more inputs. The service handler then demultiplexes the incoming requests and dispatches them synchronously to the associated request handlers.” http://en.wikipedia.org/wiki/Reactor_pattern Monday 05 March 12
def unbind puts "Connection closed" end def receive_data(data) send_data ">> #{data}" end end EM.run do EM.start_server('127.0.0.1', 9000, EchoServer) puts "Started server at 127.0.0.1:9000" end Monday 05 March 12
EM.run do EM.open_datagram_socket('127.0.0.1', 9000, EchoServer) end # Unix-domain server EM.run do EM.start_unix_domain_server('/tmp/sock', nil, EchoServer) end Monday 05 March 12
server" send_data("Why, hello there!") end def unbind puts "Connection closed" end def receive_data(data) puts ">> #{data}" end end EM.run do EM.connect('127.0.0.1', 9000, EchoClient) end Monday 05 March 12
server" send_data("Why, hello there!") end def unbind puts "Connection closed" end def receive_data(data) puts ">> #{data}" end end EM.run do EM.connect('127.0.0.1', 9000, EchoClient) end Monday 05 March 12
name callback do |who| puts "Approved #{who}!" end errback do |who| puts "Denied #{who}!" end end def approved! # succeed( *args ) set_deferred_status(:succeeded, @name) end def denied! # fail( *args ) set_deferred_status(:failed, @name) end end Monday 05 March 12
name callback do |who| puts "Approved #{who}!" end errback do |who| puts "Denied #{who}!" end end def approved! # succeed( *args ) set_deferred_status(:succeeded, @name) end def denied! # fail( *args ) set_deferred_status(:failed, @name) end end EM.run do s1 = LoanRequest.new('Marc') s1.approved! s2 = LoanRequest.new('Chris') EM.add_timer(2){ s2.denied! } end Monday 05 March 12
name callback do |who| puts "Approved #{who}!" end errback do |who| puts "Denied #{who}!" end end def approved! # succeed( *args ) set_deferred_status(:succeeded, @name) end def denied! # fail( *args ) set_deferred_status(:failed, @name) end end EM.run do s1 = LoanRequest.new('Marc') s1.approved! s2 = LoanRequest.new('Chris') EM.add_timer(2){ s2.denied! } end # :00 Approved Marc! # :02 Denied Chris! Monday 05 March 12
puts "Sent #{val}" end end def connection_open! puts 'Open connection' succeed end def connection_lost! puts 'Lost connection' set_deferred_status nil end end Monday 05 March 12
puts "Sent #{val}" end end def connection_open! puts 'Open connection' succeed end def connection_lost! puts 'Lost connection' set_deferred_status nil end end EM.run do m = Mailer.new m.add_mailing(1) m.add_mailing(2) m.connection_open! EM.add_timer(1) do m.connection_lost! EM.add_timer(2) do m.add_mailing(3) m.add_mailing(4) m.connection_open! end end end Monday 05 March 12
puts "Sent #{val}" end end def connection_open! puts 'Open connection' succeed end def connection_lost! puts 'Lost connection' set_deferred_status nil end end EM.run do m = Mailer.new m.add_mailing(1) m.add_mailing(2) m.connection_open! EM.add_timer(1) do m.connection_lost! EM.add_timer(2) do m.add_mailing(3) m.add_mailing(4) m.connection_open! end end end # Open connection # Sent 1 # Sent 2 # Lost connection # Open connection # Sent 3 # Sent 4 Monday 05 March 12