Yet another decorator
This commit is contained in:
parent
a80e101a96
commit
aa2baa62f1
3
chat.py
3
chat.py
|
@ -12,6 +12,7 @@ conn_str = '<ws "ws://localhost:8001/">'
|
||||||
cap_str = '<ref "syndicate" [] #[pkgN9TBmEd3Q04grVG4Zdw==]>'
|
cap_str = '<ref "syndicate" [] #[pkgN9TBmEd3Q04grVG4Zdw==]>'
|
||||||
cap = sturdy.SturdyRef.decode(syndicate.parse(cap_str))
|
cap = sturdy.SturdyRef.decode(syndicate.parse(cap_str))
|
||||||
|
|
||||||
|
@actor.run_system(name = 'chat', debug = False)
|
||||||
def main(turn):
|
def main(turn):
|
||||||
root_facet = turn._facet
|
root_facet = turn._facet
|
||||||
|
|
||||||
|
@ -37,5 +38,3 @@ def main(turn):
|
||||||
while line := (await reader.readline()).decode('utf-8'):
|
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.send(ds, Says(me, line.strip())))
|
||||||
actor.Turn.external(f, lambda turn: turn.stop(root_facet))
|
actor.Turn.external(f, lambda turn: turn.stop(root_facet))
|
||||||
|
|
||||||
actor.start_actor_system(main, name = 'chat', debug = False)
|
|
||||||
|
|
|
@ -14,6 +14,10 @@ _next_actor_number = IdGenerator()
|
||||||
_next_handle = IdGenerator()
|
_next_handle = IdGenerator()
|
||||||
_next_facet_id = 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):
|
def start_actor_system(boot_proc, debug = False, name = None, configure_logging = True):
|
||||||
if configure_logging:
|
if configure_logging:
|
||||||
logging.basicConfig(level = logging.DEBUG if debug else logging.INFO)
|
logging.basicConfig(level = logging.DEBUG if debug else logging.INFO)
|
||||||
|
|
Loading…
Reference in New Issue