Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think this is what you're after, although I haven't tested it.</p> <pre><code>class RestartingUserTracker def initialize @client = TweetStream::Client.new end def handle_status(status) # do whatever it is you're going to do with the status end def fetch_users accounts.get_updated_user_list end def restart @client.stop_stream users = fetch_users @client.follow(users) do |status| handle_status(status) end end end EM.run do client = RestartingUserTracker.new client.restart EM::PeriodicTimer.new(60) do client.restart end end </code></pre> <p>Here's how it works:</p> <p>TweetStream uses EventMachine internally, as a way of polling the API forever and handling the responses. I can see why you might have felt stuck, because the normal TweetStream API blocks forever and doesn't give you a way to intervene at any point. However, TweetStream does allow you to set up other things in the same <em>event loop</em>. In your case, a timer. I found the documentation on how to do that here: <a href="https://github.com/intridea/tweetstream#removal-of-on_interval-callback" rel="nofollow">https://github.com/intridea/tweetstream#removal-of-on_interval-callback</a></p> <p>By starting up our own EventMachine reactor, we're able to inject our own code into the reactor as well as use TweetStream. In this case, we're using a simple timer that just restarts the client every 60 seconds.</p> <p>EventMachine is an implementation of something called the <em>Reactor Pattern</em>. If you want to fully understand and maintain this code, it would serve you well to find some resources about it and gain a full understanding. The reactor pattern is very powerful, but can be difficult to grasp at first.</p> <p>However, this code should get you started. Also, I'd consider renaming the RestartingUserTracker to something more appropriate.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload