Skip to content

Commit eb2d183

Browse files
committed
feat: move the step parameters
1 parent 8067114 commit eb2d183

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/workflows/context/context.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
Callable,
1616
DefaultDict,
1717
Generic,
18+
Optional,
1819
Tuple,
1920
Type,
2021
TypeVar,
@@ -535,12 +536,13 @@ async def my_step(self, ctx: Context, ev: StartEvent) -> WorkerEvent | GatherEve
535536

536537
self._broker_log.append(message)
537538

538-
def send_events(self, events: list[Union[Event, Tuple[Event, str]]]) -> None:
539+
def send_events(self, events: list[Event], step: Optional[str] = None) -> None:
539540
"""
540541
Emit events manually.
541542
542543
Args:
543-
events (list[Union[Event, Tuple[Event, str]]]): a list of Event objects or of tuples containing an Event objects and the string representing the step the event should be sent to. If an Event object is used outside of a tuple, it won't be sent to any specific step.
544+
events (list[Event]): a list of Event objects to be sent
545+
step (Optional[str]): a string representing the target step to which events should be sent. Defaults to None if not set.
544546
545547
Returns:
546548
None
@@ -550,17 +552,15 @@ def send_events(self, events: list[Union[Event, Tuple[Event, str]]]) -> None:
550552
class MultipleEventsWorkflow(Workflow):
551553
@step
552554
async def send_events(self, ev: InputEvent, ctx: Context):
553-
ctx.send_events(events = [(OutputAEvent(), "step_a"), OutputBEvent()])
555+
ctx.send_events(events = [OutputAEvent(), OutputBEvent()], step="step_a")
554556
```
555557
"""
556558
for event in events:
557-
if isinstance(event, tuple):
558-
ev, step = event
559-
self._events_queue[str(type(ev))] += 1
560-
self._send_event(ev, step)
561-
else:
562-
self._events_queue[str(type(event))] += 1
559+
self._events_queue[str(type(event))] += 1
560+
if not step:
563561
self._send_event(event)
562+
else:
563+
self._send_event(event, step)
564564

565565
def receive_events(
566566
self, event: Event, event_types: list[Type[Event]]

0 commit comments

Comments
 (0)