core: setting up env neuron basically working
This commit is contained in:
parent
365cbfd5fd
commit
ed48076e67
3 changed files with 17 additions and 11 deletions
|
|
@ -8,6 +8,7 @@ from collections.abc import Awaitable, Callable, Coroutine
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
from scopes.core import actor
|
||||||
from scopes.core.message import Message
|
from scopes.core.message import Message
|
||||||
from scopes.util import keywords as k, Symbol
|
from scopes.util import keywords as k, Symbol
|
||||||
|
|
||||||
|
|
@ -45,3 +46,9 @@ def create_scope(env: Mailbox, cat=(k.csys, k.c00), **kw) -> Scope:
|
||||||
scope = Scope(environ=env, categ=cat, **kw)
|
scope = Scope(environ=env, categ=cat, **kw)
|
||||||
return scope.set_proc()
|
return scope.set_proc()
|
||||||
|
|
||||||
|
def neuron(scope: Scope) -> Mailbox:
|
||||||
|
async def process(msg: Message) -> actor.Behavior | None:
|
||||||
|
nonlocal scope
|
||||||
|
scope = await scope.proc(scope, msg)
|
||||||
|
return None if scope is None else process
|
||||||
|
return actor.create(process)
|
||||||
|
|
|
||||||
|
|
@ -10,5 +10,6 @@ async def proc_env(scope, msg):
|
||||||
await scope.environ.put(msg)
|
await scope.environ.put(msg)
|
||||||
|
|
||||||
def create(meta_env):
|
def create(meta_env):
|
||||||
return core.create_scope(meta_env, (k.env, k.c00), program=lambda x: proc_env)
|
scope = core.create_scope(meta_env, (k.env, k.c00), program=lambda x: proc_env)
|
||||||
|
return core.neuron(scope)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,8 @@ import asyncio
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from scopes import core
|
from scopes import core
|
||||||
from scopes.core import actor, environ, message
|
from scopes.core import actor, environ
|
||||||
|
from scopes.core.message import Message
|
||||||
from scopes.util import keywords as k
|
from scopes.util import keywords as k
|
||||||
|
|
||||||
collector = []
|
collector = []
|
||||||
|
|
@ -32,11 +33,8 @@ async def test_actor():
|
||||||
async with asyncio.TaskGroup() as group:
|
async with asyncio.TaskGroup() as group:
|
||||||
q1 = actor.create(handle_basic, group)
|
q1 = actor.create(handle_basic, group)
|
||||||
q2 = actor.create(handle_basic, group)
|
q2 = actor.create(handle_basic, group)
|
||||||
await q1.put(message.Message(k.test, k.hello))
|
msgs = [Message(k.test, k.hello), k.show, k.switch, k.show, "actor 1: Goodbye"]
|
||||||
await q1.put(k.show)
|
await asyncio.gather(*[q1.put(m) for m in msgs])
|
||||||
await q1.put(k.switch)
|
|
||||||
await q1.put(k.show)
|
|
||||||
await q1.put("actor 1: Goodbye")
|
|
||||||
await q2.put("actor 2")
|
await q2.put("actor 2")
|
||||||
await q2.put(k.show)
|
await q2.put(k.show)
|
||||||
await q1.put(k.quit)
|
await q1.put(k.quit)
|
||||||
|
|
@ -47,7 +45,7 @@ async def test_actor():
|
||||||
|
|
||||||
|
|
||||||
def test_message():
|
def test_message():
|
||||||
msg = message.Message(k.test, k.data, 'person', '4711',
|
msg = Message(k.test, k.data, 'person', '4711',
|
||||||
data=dict(firstName='Bob', lastName='Miller'))
|
data=dict(firstName='Bob', lastName='Miller'))
|
||||||
assert msg.head['class'] is k.person
|
assert msg.head['class'] is k.person
|
||||||
assert msg.addr() == (k.test, k.person, '4711')
|
assert msg.addr() == (k.test, k.person, '4711')
|
||||||
|
|
@ -66,8 +64,8 @@ async def meta_env(coll):
|
||||||
|
|
||||||
@pytest.mark.anyio
|
@pytest.mark.anyio
|
||||||
async def test_core(meta_env, coll):
|
async def test_core(meta_env, coll):
|
||||||
env_scope = environ.create(meta_env)
|
env = environ.create(meta_env)
|
||||||
assert env_scope.value == 0
|
await env.put(Message(k.env, k.hello))
|
||||||
#print(meta_env)
|
|
||||||
await asyncio.sleep(0.01)
|
await asyncio.sleep(0.01)
|
||||||
|
print(coll)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue