Async Streaming Examples

This guide provides practical examples demonstrating the powerful async streaming capabilities of UESynth for high-performance data collection scenarios.

Overview

Async streaming enables:

  • Non-blocking operations - Send requests without waiting

  • High throughput - 100-1000+ operations per second

  • Concurrent execution - Multiple operations in parallel

  • Real-time responsiveness - Minimal latency accumulation

Basic Async Pattern

import asyncio
import cv2
from uesynth import AsyncUESynthClient

async def basic_async_capture():
    """Basic pattern for async data capture."""
    
    async with AsyncUESynthClient() as client:
        # Start a capture (non-blocking)
        request_id = await client.capture.rgb(width=1920, height=1080)
        print(f"Started capture request: {request_id}")
        
        # Do other work while capture is processing
        await client.camera.set_location(x=100, y=200, z=50)
        
        # Get the captured frame
        frame = await client.get_latest_frame()
        if frame is not None:
            cv2.imwrite("async_capture.png", frame)
            print("✅ Frame captured and saved")

asyncio.run(basic_async_capture())

High-Performance Collection

Real-time Simulation

Producer-Consumer Pattern

Error Handling & Resilience

Performance Tips

1. Use Streaming for High Throughput

2. Batch Operations

3. Configure for Performance

These examples demonstrate the power and flexibility of UESynth's async streaming capabilities. Choose the pattern that best fits your specific use case.

Next Steps

Last updated