diff --git a/scopes/core/__init__.py b/scopes/core/__init__.py new file mode 100644 index 0000000..1d165e4 --- /dev/null +++ b/scopes/core/__init__.py @@ -0,0 +1 @@ +"""package scopes.core""" diff --git a/scopes/core/actor.py b/scopes/core/actor.py new file mode 100644 index 0000000..87fa195 --- /dev/null +++ b/scopes/core/actor.py @@ -0,0 +1,33 @@ +""" package scopes.core.actor """ + +import asyncio + +quit = object() + +async def loop(q, bhv): + while True: + msg = await q.get() + if msg == quit: + break + bhv(msg) + +def create(q, bhv): + return asyncio.create_task(loop(q, bhv)) + +# some simple behaviors + +def show(msg): + print(msg) + +# main + +async def main(): + q = asyncio.Queue() + task = create(q, show) + await q.put("Hello World!") + await q.put(quit) + await task + +def run(): + asyncio.run(main()) +