Wait for `.notify`. Returns a `.Future` that resolves ``True`` if the condition is notified, or ``False`` after a timeout.
(
self, timeout: Optional[Union[float, datetime.timedelta]] = None
)
| 117 | return result + ">" |
| 118 | |
| 119 | def wait( |
| 120 | self, timeout: Optional[Union[float, datetime.timedelta]] = None |
| 121 | ) -> Awaitable[bool]: |
| 122 | """Wait for `.notify`. |
| 123 | |
| 124 | Returns a `.Future` that resolves ``True`` if the condition is notified, |
| 125 | or ``False`` after a timeout. |
| 126 | """ |
| 127 | waiter = Future() # type: Future[bool] |
| 128 | self._waiters.append(waiter) |
| 129 | if timeout: |
| 130 | |
| 131 | def on_timeout() -> None: |
| 132 | if not waiter.done(): |
| 133 | future_set_result_unless_cancelled(waiter, False) |
| 134 | self._garbage_collect() |
| 135 | |
| 136 | io_loop = ioloop.IOLoop.current() |
| 137 | timeout_handle = io_loop.add_timeout(timeout, on_timeout) |
| 138 | waiter.add_done_callback(lambda _: io_loop.remove_timeout(timeout_handle)) |
| 139 | return waiter |
| 140 | |
| 141 | def notify(self, n: int = 1) -> None: |
| 142 | """Wake ``n`` waiters.""" |