Make call_on_each_{message,event} examples more clear

Before these examples weren't obviously blocking calls (they seemed
more like a callback registration, which may make more sense in the future)

(imported from commit 78fdf98d791b19843526437c710901d8dff62e8c)
This commit is contained in:
acrefoot 2013-09-24 11:47:00 -04:00 committed by Zev Benjamin
parent 49a55ca6fa
commit c5f8ffc767
2 changed files with 4 additions and 0 deletions

View File

@ -45,4 +45,5 @@ client = zulip.init_from_options(options)
def print_message(message):
print message
# This is a blocking call, and will continuously poll for new messages
client.call_on_each_message(print_message)

View File

@ -88,9 +88,12 @@ to pull out the resulting HTML :)
<span class="p">})</span>
<span class="c"># Print each message the user receives</span>
<span class="c"># This is a blocking call that will run forever</span>
<span class="n">client</span><span class="o">.</span><span class="n">call_on_each_message</span><span class="p">(</span><span class="k">lambda</span> <span class="n">msg</span><span class="p">:</span> <span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span> <span class="o">+</span> <span class="s">"</span><span class="se">\n</span><span class="s">"</span><span class="p">))</span>
<span class="c"># Print every event relevant to the user</span>
<span class="c"># This is a blocking call that will run forever</span>
<span class="c"># This will never be reached unless you comment out the previous line</span>
<span class="n">client</span><span class="o">.</span><span class="n">call_on_each_event</span><span class="p">(</span><span class="k">lambda</span> <span class="n">msg</span><span class="p">:</span> <span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span> <span class="o">+</span> <span class="s">"</span><span class="se">\n</span><span class="s">"</span><span class="p">))</span>
</pre></div>
</div>