Created
December 8, 2010 16:53
-
-
Save svenfuchs/733541 to your computer and use it in GitHub Desktop.
attach stdout to eventmachine
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' | |
class Sender < EventMachine::Connection | |
attr_reader :connection | |
def initialize | |
@connection = EM.connect('127.0.0.1', 9797) | |
end | |
def receive_data(data) | |
connection.send_data(data) | |
end | |
def unbind | |
EM.stop | |
end | |
end | |
EM.run do | |
EM.attach $stdin, Sender | |
end | |
# ruby -e '$stdout.sync = true; 10.times { print "."; sleep(0.5) }' | ruby sender.rb |
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' | |
$stdout.sync = true | |
class ReadFromWorker < EventMachine::Connection | |
def receive_data(data) | |
print data | |
end | |
end | |
EM.run do | |
EM.start_server('127.0.0.1', 9797, ReadFromWorker) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment