Skip to content

Commit 210156b

Browse files
committed
Add broadcast support
1 parent 8bfad65 commit 210156b

3 files changed

Lines changed: 34 additions & 3 deletions

File tree

example/joe.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
@actor.timer_action(every=1000)
1818
def hi(ctx: Context) -> Value:
1919
new_state = None
20+
broadcast = Broadcast()
21+
broadcast.channel = "test"
22+
broadcast.action_name = "setLanguage"
23+
broadcast.value = Request()
24+
2025
if not ctx.state:
2126
new_state = JoeState()
2227
new_state.languages.append("portuguese")
@@ -25,6 +30,7 @@ def hi(ctx: Context) -> Value:
2530

2631
return Value()\
2732
.of("test")\
33+
.broadcast(broadcast)\
2834
.state(new_state)\
2935
.reply()
3036

@@ -33,7 +39,7 @@ def hi(ctx: Context) -> Value:
3339
def set_language(request: Request, ctx: Context) -> Value:
3440
return Value()\
3541
.of("test")\
36-
.broadcast(Broadcast())\
42+
.broadcast()\
3743
.effect(Effect())\
3844
.metada(Metadata())\
3945
.state({})\
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11

2+
from dataclasses import dataclass
3+
4+
5+
@dataclass
26
class Broadcast:
3-
def __init__(self):
4-
pass
7+
channel: str = None
8+
action_name: str = None
9+
value: any = None

spawn/eigr/functions/actors/internal/controller.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
Noop,
3737
RegistrationRequest,
3838
ServiceInfo,
39+
Broadcast
3940
)
4041

4142
from google.protobuf import symbol_database as _symbol_database
@@ -100,9 +101,28 @@ def handle_response(system, actor_name, result):
100101
elif result.get_reply_kind == ReplyKind.REPLY:
101102
actor_invocation_response.value = pack(result.get_response())
102103

104+
if result.get_broadcast() != None:
105+
value_broadcast = result.get_broadcast()
106+
broadcast = handle_broadcast(value_broadcast)
107+
actor_invocation_response.workflow.broadcast.CopyFrom(broadcast)
108+
103109
return actor_invocation_response
104110

105111

112+
def handle_broadcast(value_broadcast):
113+
broadcast = Broadcast()
114+
broadcast.channel_group = value_broadcast.channel
115+
broadcast.action_name = value_broadcast.action_name
116+
117+
if value_broadcast.value == None:
118+
broadcast.noop = Noop()
119+
else:
120+
value = pack(value_broadcast.value)
121+
broadcast.value.CopyFrom(value)
122+
123+
return broadcast
124+
125+
106126
class ActorController:
107127
_instance = None
108128

0 commit comments

Comments
 (0)