How to intercept an (infinite) stream?
I am working with the ExTwitter library and would like to be able to sometimes kill the streaming API call to change the parameters.
My current code looks something like this:
for tweet <- ExTwitter.stream_filter(track: terms) do
process_tweet tweet
end
Is there anything I can do to indicate that I no longer need messages?
+3
Tim McNamara
source
to share
2 answers
Thanks for giving it a try. I could confirm that Chris pointed out the job. As an alternative approach, I've put one test as an API method call in the next (although I'm not sure how to properly accept an infinite stream).
https://github.com/parroty/extwitter/issues/2
+2
parroty
source
to share
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
+5
Chris McCord
source
to share