swactor/examples/hello_single_thread.py
zacheryasc 65614e14d3 feat: python bindings (#7)
Python bindings allowing us to interact with the library in a python REPL


Signed-off-by: Zachery Aaron Shores-Chmielewski <zacheryasc@gmail.com>
2026-02-06 12:47:51 +00:00

13 lines
323 B
Python

"""Hello world: spawn an echo actor, send a message, get it back."""
from swactor import Runtime
def echo(ctx, msg):
ctx.send(msg["reply_to"], f"hello, {msg['name']}!")
rt = Runtime()
addr = rt.spawn(echo)
inbox = rt.inbox()
rt.send(addr, {"name": "world", "reply_to": inbox.addr})
rt.tick()
print(inbox.try_recv())