code: def wait_idle(self, timeout=1.0):
          async def _awaiter():
              background_work = {x.join() for x in self._work_queues}
              for event in self._events:
                  if not event.is_set():
                      background_work.add(event.wait())
              _done, pending = await asyncio.wait(background_work, timeout=timeout)
              if len(pending) > 0:
                  raise TimeoutExpiredError("Timeout waiting for event loop to become idle", pending=pending)
          if self._on_emulation_thread():
              return asyncio.wait_for(_awaiter(), timeout=timeout)
          self.run_task_external(_awaiter())
          return None