MessageQueue (message_queue.py)

phone-call-assistant · email, pub-sub, realtime-sync, core

Copyright (c) Microsoft Corporation. Licensed under the MIT license.

# Source: https://github.com/gawyli/phone-call-assistant | License: MIT
# Provided via justclaw.it.com; keep this notice with the code.
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

import asyncio
from collections.abc import Awaitable, Callable
from typing import Generic, Optional, TypeVar

T = TypeVar("T")


class MessageQueue(Generic[T]):
    def __init__(self, receive_delegate: Callable[[], Awaitable[T]]):
        self._stored_messages: list[T] = []
        self.waiting_receivers: list[tuple[Callable[[T], bool], asyncio.Future]] = []
        self.is_polling: bool = False
        self.receive_delegate = receive_delegate
        self.poll_task: Optional[asyncio.Task] = None

    def _push_back(self, message: T):
        self._stored_messages.append(message)

  

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search 40K more like it.

Get a free API key