Skip to content

Commit

Permalink
check to see if the reactor is running before starting EM
Browse files Browse the repository at this point in the history
  • Loading branch information
stve committed Dec 8, 2011
1 parent faf26e6 commit 5a13f0f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/tweetstream/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,16 @@ def on_interval(time_interval=nil, &block)

# connect to twitter while starting a new EventMachine run loop
def start(path, query_parameters = {}, &block)
EventMachine.epoll
EventMachine.kqueue

EventMachine::run {
if EventMachine.reactor_running?
connect(path, query_parameters, &block)
}
else
EventMachine.epoll
EventMachine.kqueue

EventMachine::run do
connect(path, query_parameters, &block)
end
end
end

# connect to twitter without starting a new EventMachine run loop
Expand Down Expand Up @@ -405,6 +409,7 @@ def connect(path, query_parameters = {}, &block)
@stream.on_max_reconnects do |timeout, retries|
raise TweetStream::ReconnectError.new(timeout, retries)
end

@stream
end

Expand Down

0 comments on commit 5a13f0f

Please sign in to comment.