23 lines
428 B
Python
23 lines
428 B
Python
# scopes.core.actor
|
|
|
|
import asyncio
|
|
|
|
from scopes import util
|
|
|
|
quit = util.Symbol("quit")
|
|
|
|
async def loop(q, bhv):
|
|
while True:
|
|
msg = await q.get()
|
|
if msg is 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
|
|
|