-
-
Save larrytheliquid/177894 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
require 'rubygems' | |
require 'eventmachine' | |
require 'em-http' | |
require 'dataflow' | |
Thread.new { | |
EM.run{} | |
} | |
module EventMachine | |
module DataflowDeferrable | |
include Dataflow | |
declare :results | |
def succeeded? | |
barrier results | |
@deferred_status == :succeeded | |
end | |
def failed? | |
barrier results | |
@deferred_status == :failed | |
end | |
def set_deferred_status(status, *args) | |
@deferred_status = status | |
unify results, @deferred_args | |
end | |
end | |
end | |
class EventMachine::HttpClient | |
include EventMachine::DataflowDeferrable | |
end | |
def dataflow_http | |
results = %w(http://www.yahoo.com/ http://www.slashdot.org/ http://www.github.com/ http://www.oib.com/).map do |url| | |
EventMachine::HttpRequest.new(url).get | |
end | |
results.each do |http| | |
if http.succeeded? | |
p http.response | |
else | |
p "bad stuff happened" | |
end | |
end | |
end | |
dataflow_http |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment