Async patterns
Consume IConvaiOperation<T> and IConvaiStream<T> using async/await, coroutines, chaining, progress tracking, cancellation, and streams.
Async/await
using Convai.Runtime.Core.Async;
using Convai.Runtime.Facades;
using System.Threading;
using UnityEngine;
public class AsyncConnectExample : MonoBehaviour
{
private async void Start()
{
var manager = ConvaiManager.ActiveManager;
if (manager == null) return;
try
{
var session = await manager.ConnectAsync(destroyCancellationToken);
Debug.Log($"Connected. Room: {session.RoomId}");
}
catch (ConvaiOperationException ex)
{
Debug.LogError($"[{ex.Code}] Connect failed: {ex.Message}");
}
catch (OperationCanceledException)
{
Debug.Log("Connect canceled — scene unloaded.");
}
}
}await operation vs. await operation.AsTask()
await operation vs. await operation.AsTask()Coroutines
ContinueWith chaining
Progress tracking
Cancellation
Using CancellationToken
CancellationTokenUsing destroyCancellationToken
destroyCancellationTokenUsing operation.Cancel()
operation.Cancel()CancellationToken vs. operation.Cancel()
CancellationToken vs. operation.Cancel()Streams
Error handling decision table
Scenario
Pattern
Reason
Usage examples
Example 1 — Loading overlay with progress bar and cancel button
Example 2 — Streaming transcript tokens to a custom log widget
Troubleshooting
Symptom
Likely Cause
Fix
Next steps
Last updated
Was this helpful?