async
Soul provides powerful asynchronous programming capabilities throughasync
functions and await
expressions, enabling non-blocking operations and efficient handling of I/O-bound tasks.
Async Functions
Async functions are declared using theasync soul
keywords and automatically return a Promise:
Await Expressions
Theawait
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 withawait
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
- Use async for I/O operations: Network requests, file operations, AI calls
- Handle errors properly: Always wrap await calls in try-catch when needed
- Don’t block unnecessarily: Use async/await for truly asynchronous operations
- Combine with concurrency: Use
Concurrency.spawn
for parallel async operations