GitHub user hanishi edited a discussion: pekko-py: Pekko Typed style actors for 
Python asyncio

https://github.com/hanishi/pekko-py

With Python's `match`, frozen dataclasses, and `type` unions, it reads close to 
the Scala DSL:

```python
@dataclass(frozen=True)
class Increment:
    by: int

@dataclass(frozen=True)
class GetTotal:
    reply_to: ActorRef[int]

type Command = Increment | GetTotal

def counter(total: int = 0) -> Behavior[Command]:
    def on_message(msg: Command) -> Behavior[Command]:
        match msg:
            case Increment(by):
                return counter(total + by)
            case GetTotal(reply_to):
                reply_to.tell(total)
                return Behaviors.same
    return Behaviors.receive_message(on_message)
```



GitHub link: https://github.com/apache/pekko/discussions/3642

----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: 
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to