MCPcopy
hub / github.com/tornadoweb/tornado / wait

Method wait

tornado/locks.py:231–255  ·  view source on GitHub ↗

Block until the internal flag is true. Returns an awaitable, which raises `tornado.util.TimeoutError` after a timeout.

(
        self, timeout: Optional[Union[float, datetime.timedelta]] = None
    )

Source from the content-addressed store, hash-verified

229 self._value = False
230
231 def wait(
232 self, timeout: Optional[Union[float, datetime.timedelta]] = None
233 ) -> Awaitable[None]:
234 """Block until the internal flag is true.
235
236 Returns an awaitable, which raises `tornado.util.TimeoutError` after a
237 timeout.
238 """
239 fut = Future() # type: Future[None]
240 if self._value:
241 fut.set_result(None)
242 return fut
243 self._waiters.add(fut)
244 fut.add_done_callback(lambda fut: self._waiters.remove(fut))
245 if timeout is None:
246 return fut
247 else:
248 timeout_fut = gen.with_timeout(timeout, fut)
249 # This is a slightly clumsy workaround for the fact that
250 # gen.with_timeout doesn't cancel its futures. Cancelling
251 # fut will remove it from the waiters list.
252 timeout_fut.add_done_callback(
253 lambda tf: fut.cancel() if not fut.done() else None
254 )
255 return timeout_fut
256
257
258class _ReleasingContextManager:

Calls 2

addMethod · 0.80
doneMethod · 0.45