Skip to main content
Streaming execution provides real-time output as your code runs. Instead of waiting for completion, you receive stdout and stderr messages as theyโ€™re generated, perfect for monitoring long-running tasks.

Overview

Streaming execution is ideal for:
  • Long-running tasks where you want real-time progress
  • Interactive code that produces output over time
  • Monitoring execution progress
  • Building real-time dashboards or UIs
Streaming execution uses WebSocket connections for real-time communication. It requires async/await support in your code.

Basic Streaming

Stream execution output in real-time:

Message Types

Stream messages have different types:

Progress Monitoring

Monitor progress of long-running tasks:

Environment Variables

Pass environment variables to streaming execution:

Error Handling

Handle errors in streaming execution:

Complete Example

Hereโ€™s a complete example with real-time progress:

Best Practices

1

1. Use Async/Await

Streaming execution requires async/await. Make sure your code uses async functions and async for loops.
2

2. Handle All Message Types

Process stdout, stderr, result, and complete messages appropriately for a complete streaming experience.
3

3. Break on Complete

Always break the loop when you receive a โ€˜completeโ€™ message to avoid unnecessary processing.
4

4. Handle Errors

Check exit codes and success flags to handle execution failures gracefully.
5

5. Use for Real-Time Feedback

Streaming is best for tasks where real-time output is valuable. For simple scripts, synchronous execution may be simpler.

Next Steps