3

I'm working with the ExTwitter library and would like to be able to occasionally kill a call to the streaming API to change parameters.

My current code looks something like this:

for tweet <- ExTwitter.stream_filter(track: terms) do
    process_tweet tweet
end

Is there anything I could do to indicate that I don't want any more messages?

Tim McNamara
  • 18,019
  • 4
  • 52
  • 83

2 Answers2

5

You can throw an exception and catch it:

try do
  for tweet <- ExTwitter.stream_filter(track: terms) do
    process_tweet tweet
    if logic_to_determine_halt?, do: throw :halt
  end
catch 
  :halt -> #finished
end
Chris McCord
  • 8,020
  • 1
  • 37
  • 26
2

Thanks for trying out. I could confirm the method Chris indicated works. As an alternative approach, I put one trial as an API method call in the following (though I'm not confident how to take infinite stream properly yet).

https://github.com/parroty/extwitter/issues/2

parroty
  • 1,385
  • 9
  • 12