Skip to content

Instantly share code, notes, and snippets.

@larrytheliquid
Forked from bpot/gist:177574
Created August 30, 2009 07:05
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save larrytheliquid/177894 to your computer and use it in GitHub Desktop.
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