如何中断(无限)流?

时间:2014-08-07 03:32:49

标签: elixir twitter-streaming-api

我正在使用ExTwitter库,并且希望能够偶尔杀死对流API的调用以更改参数。

我当前的代码看起来像这样:

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

我能做些什么来表明我不想要更多的消息吗?

2 个答案:

答案 0 :(得分:5)

你可以抛出异常并抓住它:

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

答案 1 :(得分:2)

感谢您的尝试。我可以确认Chris指出的方法有效。作为一种替代方法,我在下面将一个试验作为API方法调用(尽管我不确定如何正确地采用无限流)。

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

相关问题