Simple demonstration of using masterror in async Rust code with tokio.
- Async Error Handling - Using
?operator in async functions - Timeout Handling - Converting tokio timeout errors to AppError
- Error Propagation - Clean error propagation through async call chains
- Result Types - Using
AppResult<T>for async operations
cd examples/basic-async
cargo runasync fn fetch_data(id: u64) -> Result<String, AppError> {
if id == 0 {
return Err(AppError::validation("ID cannot be zero"));
}
Ok(format!("Data for ID {}", id))
}use tokio::time::{timeout, Duration};
let result = timeout(
Duration::from_secs(5),
fetch_data(123)
).await?; // Converts Elapsed to AppError::Timeoutasync fn process() -> Result<(), AppError> {
let data = fetch_data(123).await?;
let result = process_data(&data).await?;
save_result(result).await?;
Ok(())
}MIT