initial revision

This commit is contained in:
Timothy Pogue
2022-11-14 20:27:45 -07:00
parent a951b49541
commit 659c8c237f
7 changed files with 494 additions and 241 deletions

View File

@@ -0,0 +1,23 @@
import asyncio
class MessageStream:
"""
A message stream for consumers to subscribe to,
and for producers to publish to.
"""
def __init__(self):
self._loop = asyncio.get_running_loop()
self._waiter = self._loop.create_future()
def publish(self, message):
waiter, self._waiter = self._waiter, self._loop.create_future()
waiter.set_result((message, self._waiter))
async def subscribe(self):
waiter = self._waiter
while True:
message, waiter = await waiter
yield message
__aiter__ = subscribe