Skip to main content

async

Soul provides powerful asynchronous programming capabilities through async functions and await expressions, enabling non-blocking operations and efficient handling of I/O-bound tasks.

Async Functions

Async functions are declared using the async soul keywords and automatically return a Promise:

Await Expressions

The await keyword is used to wait for async operations to complete:

Function Parameters

Async functions support parameters with default values:

Error Handling

Async functions work seamlessly with try-catch blocks:

Calling Async Functions

Async functions must be called with await or handled as promises:

Combining with Concurrency

Async functions work well with Soul’s concurrency features:

Common Use Cases

Network Operations

File Operations

AI Integration

Best Practices

  1. Use async for I/O operations: Network requests, file operations, AI calls
  2. Handle errors properly: Always wrap await calls in try-catch when needed
  3. Don’t block unnecessarily: Use async/await for truly asynchronous operations
  4. Combine with concurrency: Use Concurrency.spawn for parallel async operations