base_post_delivery.py 861 B

12345678910111213141516171819
  1. """Running a turn's one-shot post-delivery callback (``BasePlatformAdapter.register_post_delivery_callback``).
  2. Shared by the adapter task that delivered a messaging reply (``_process_message_background``) and the
  3. session authority's drain, which settles every turn no adapter task brackets (``session_ingress``).
  4. """
  5. import asyncio
  6. import contextlib
  7. import inspect
  8. from typing import Any
  9. async def run_post_delivery_callback(callback: Any, timeout: float) -> None:
  10. """Run *callback* (a no-op when None): bounded, errors swallowed, so a stuck or failing callback
  11. never holds up the session whose reply it follows."""
  12. if callable(callback):
  13. with contextlib.suppress(asyncio.TimeoutError, Exception):
  14. result = callback()
  15. if inspect.isawaitable(result):
  16. await asyncio.wait_for(result, timeout=timeout)