Async Execution
The async keyword enables parallel execution of AI calls and other operations.
Basic Async
Section titled “Basic Async”Run multiple AI calls concurrently:
async let summary = do "Summarize this document"async let keywords: text[] = do "Extract 5 keywords"async let sentiment: text = do "What is the sentiment?"
// All three run concurrently// They're automatically awaited when usedlet report = do "Create a report using: {summary}, {keywords}, {sentiment}"How It Works
Section titled “How It Works”asyncdeclarations start executing immediately- Execution continues without waiting
- Values are automatically awaited when accessed
- Runtime waits for all async operations before completing
Async Declarations
Section titled “Async Declarations”Async Let
Section titled “Async Let”async let result = do "Long running task"// Continue immediately, result awaited when usedAsync Const
Section titled “Async Const”async const data: json = do "Fetch data"Async with Types
Section titled “Async with Types”async let count: number = do "How many items?"async let names: text[] = do "List the names"Async Destructuring
Section titled “Async Destructuring”async let { title: text, body: text } = do "Generate article"Async Statements
Section titled “Async Statements”Fire-and-forget operations:
// Log event without waitingasync do "Log: user clicked button" logger
// Background processingasync vibe "Process this data in the background" agent
// Async TypeScriptasync ts() { await sendAnalytics(event);}
// Async function callasync notifyUser(userId, message)Parallel Processing
Section titled “Parallel Processing”Multiple Independent Tasks
Section titled “Multiple Independent Tasks”async let translation_es = do "Translate to Spanish: {text}"async let translation_fr = do "Translate to French: {text}"async let translation_de = do "Translate to German: {text}"
// All three translations happen in parallellet results = { spanish: translation_es, french: translation_fr, german: translation_de}Batch Analysis
Section titled “Batch Analysis”// Start all analyses concurrentlyasync let sentiment = do "Analyze sentiment"async let topics = do "Extract topics"async let entities = do "Find named entities"async let summary = do "Write summary"
// Combine results (auto-awaited)let analysis = { sentiment: sentiment, topics: topics, entities: entities, summary: summary}Async with Different Models
Section titled “Async with Different Models”model fast = { name: "claude-haiku-4-5-20251001", ... }model smart = { name: "claude-opus-4-5-20251101", ... }
// Use fast model for simple tasks, smart for complexasync let quickCheck = do "Is this valid?" fastasync let deepAnalysis = do "Detailed analysis" smart
// Both run in parallel despite different modelsAsync in Loops
Section titled “Async in Loops”let urls = ["url1", "url2", "url3"]let fetches: text[] = []
for url in urls { // Each iteration's fetch starts immediately async let content = fetch(url) fetches.push(content)}
// All fetches complete before loop exitsBest Practices
Section titled “Best Practices”Do Parallelize Independent Work
Section titled “Do Parallelize Independent Work”// Good - independent tasks in parallelasync let a = do "Task A"async let b = do "Task B"async let c = do "Task C"let combined = processResults(a, b, c)Don’t Parallelize Dependent Work
Section titled “Don’t Parallelize Dependent Work”// Bad - B depends on Aasync let a = do "Get data"async let b = do "Process {a}" // a might not be ready!
// Good - sequential for dependencieslet a = do "Get data"let b = do "Process {a}"Use Async for I/O Operations
Section titled “Use Async for I/O Operations”// Good - parallel I/Oasync let file1 = readFile("a.txt")async let file2 = readFile("b.txt")async let file3 = readFile("c.txt")Fire-and-Forget for Logging
Section titled “Fire-and-Forget for Logging”// Log without blocking main executionasync do "Log event: {event}" logger// Continue immediatelyprocessNextItem()Comparison with Sequential
Section titled “Comparison with Sequential”Sequential (Slow)
Section titled “Sequential (Slow)”let a = do "Task A" // Wait...let b = do "Task B" // Wait...let c = do "Task C" // Wait...// Total time: A + B + CParallel (Fast)
Section titled “Parallel (Fast)”async let a = do "Task A" // Startasync let b = do "Task B" // Startasync let c = do "Task C" // Start// Total time: max(A, B, C)let result = combine(a, b, c) // Auto-await