I'm running a streaming connection with twitter gem inside a thread. I have been disconnecting by simply killing the thread and opening a new one. I have an overlap between the old and new threads so I don't miss anything (hopefully).
But if I kill a few quickly, I receive a Exceeded connection limit for user
error from the API. This is because twitter only allows 2 connections at once. It seems like the connection is still open...
Is there a way to disconnect using the twitter gem? I want to disconnect the streams before I kill the thread so I know how many are open.
My code looks something like this:
thred = Thread.new do
client = ::Twitter::Streaming::Client.new(..config..)
client.filter(follow: '1,2,44') do |tweet|
// do stuff
end
end
And I am killing them like so:
thred.kill
But I want to run something like:
client.disconnect
And then tidy up dead threads or something...