Yet another decorator

This commit is contained in:
Tony Garnock-Jones 2021-08-19 17:09:07 -04:00
parent a80e101a96
commit aa2baa62f1
2 changed files with 5 additions and 2 deletions

View File

@ -12,6 +12,7 @@ conn_str = '<ws "ws://localhost:8001/">'
cap_str = '<ref "syndicate" [] #[pkgN9TBmEd3Q04grVG4Zdw==]>'
cap = sturdy.SturdyRef.decode(syndicate.parse(cap_str))
@actor.run_system(name = 'chat', debug = False)
def main(turn):
root_facet = turn._facet
@ -37,5 +38,3 @@ def main(turn):
while line := (await reader.readline()).decode('utf-8'):
actor.Turn.external(f, lambda turn: turn.send(ds, Says(me, line.strip())))
actor.Turn.external(f, lambda turn: turn.stop(root_facet))
actor.start_actor_system(main, name = 'chat', debug = False)

View File

@ -14,6 +14,10 @@ _next_actor_number = IdGenerator()
_next_handle = IdGenerator()
_next_facet_id = IdGenerator()
# decorator
def run_system(**kwargs):
return lambda boot_proc: start_actor_system(boot_proc, **kwargs)
def start_actor_system(boot_proc, debug = False, name = None, configure_logging = True):
if configure_logging:
logging.basicConfig(level = logging.DEBUG if debug else logging.INFO)