[PR #159] [CLOSED] Powerful event listeners #175

Closed
opened 2026-02-16 02:16:49 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/run-llama/workflows-py/pull/159
Author: @johnmalek312
Created: 10/23/2025
Status: Closed

Base: mainHead: main


📝 Commits (2)

📊 Changes

2 files changed (+49 additions, -3 deletions)

View changed files

📝 src/workflows/context/context.py (+35 -2)
📝 src/workflows/handler.py (+14 -1)

📄 Description

PR allowing event listeners to modify workflow events without race condition.

eg:

class MyEvent(Event):
    value: int


class MyWorkflow(Workflow):
    @step
    async def start(self, ctx: Context, _ev: StartEvent) -> StopEvent:
        event = MyEvent(value=1)

        await ctx.write_event_to_stream(event, wait=True)

        assert event.value == 100
        return StopEvent(result=event.value)


async def main():
    workflow = MyWorkflow(timeout=10, verbose=False)
    handler = workflow.run()

    async for event in handler.stream_events():
        if isinstance(event, MyEvent):
            time.sleep(3) # doing something here
            event.value = 100

    result = await handler
    assert result == 100
    print("✅ Test passed")

backward compatible


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/run-llama/workflows-py/pull/159 **Author:** [@johnmalek312](https://github.com/johnmalek312) **Created:** 10/23/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `main` --- ### 📝 Commits (2) - [`cbc1485`](https://github.com/run-llama/workflows-py/commit/cbc1485e2f5d4ff07c6cf8fa6a033648747a3d7a) wait for event listener - [`898ea78`](https://github.com/run-llama/workflows-py/commit/898ea78ec8ddcfe8f9c72f6e4f6edbac23544740) cleanup and typing ### 📊 Changes **2 files changed** (+49 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `src/workflows/context/context.py` (+35 -2) 📝 `src/workflows/handler.py` (+14 -1) </details> ### 📄 Description PR allowing event listeners to modify workflow events without race condition. eg: ```python class MyEvent(Event): value: int class MyWorkflow(Workflow): @step async def start(self, ctx: Context, _ev: StartEvent) -> StopEvent: event = MyEvent(value=1) await ctx.write_event_to_stream(event, wait=True) assert event.value == 100 return StopEvent(result=event.value) async def main(): workflow = MyWorkflow(timeout=10, verbose=False) handler = workflow.run() async for event in handler.stream_events(): if isinstance(event, MyEvent): time.sleep(3) # doing something here event.value = 100 result = await handler assert result == 100 print("✅ Test passed") ``` backward compatible --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-16 02:16:49 -05:00
yindo closed this issue 2026-02-16 02:16:49 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: run-llama/workflows-py#175