From 7ecc0312c57ffe948c8341a2158e0d3a419822bb Mon Sep 17 00:00:00 2001 From: "A. Jesse Jiryu Davis" Date: Fri, 27 Mar 2015 06:17:31 -0400 Subject: [PATCH] Document locks.Event. --- docs/locks.rst | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/docs/locks.rst b/docs/locks.rst index 41c1e2bd..c0350dac 100644 --- a/docs/locks.rst +++ b/docs/locks.rst @@ -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