Document locks.Event.

This commit is contained in:
A. Jesse Jiryu Davis 2015-03-27 06:17:31 -04:00
parent 4dd78cffa1
commit 7ecc0312c5
1 changed files with 45 additions and 0 deletions

View File

@ -72,3 +72,48 @@ multithreaded app.)*
The method raises `tornado.gen.TimeoutError` if there's no notification
before the deadline.
Event
-----
.. autoclass:: Event
:members:
A coroutine can wait for an event to be set. Once it is set, the coroutine
does not block on `wait` until the the event is unset again:
.. testcode::
from tornado import ioloop, gen, locks
io_loop = ioloop.IOLoop.current()
event = locks.Event()
@gen.coroutine
def waiter():
print("Waiting for event")
yield event.wait()
print("Not waiting this time")
yield event.wait()
print("Done")
@gen.coroutine
def setter():
print("About to set the event")
event.set()
@gen.coroutine
def runner():
yield [waiter(), setter()]
io_loop.run_sync(runner)
.. testoutput::
Waiting for event
About to set the event
Not waiting this time
Done