py-scopes/scopes/core/actor.py

21 lines
416 B
Python

# scopes.core.actor
import asyncio
from scopes.util import keywords as k
async def loop(q, bhv):
while True:
msg = await q.get()
if msg is k.quit:
break
bhv = await bhv(msg) or bhv
def create(bhv, group=None):
q = asyncio.Queue()
if group is None:
return q, asyncio.create_task(loop(q, bhv))
else:
group.create_task(loop(q, bhv))
return q