Basic Usage
Theupdate function can optionally return a Task:
Task::perform
Task::perform runs an async function and maps its result to a message:
Task::none
When no asynchronous work is needed:Batching Tasks
Run multiple tasks concurrently:Chaining Tasks
Execute tasks sequentially:Mapping Tasks
Transform the message produced by a task:Task with Function
UseFunction::with to curry message constructors:
Abortable Tasks
Create tasks that can be cancelled:Sipping from Streams
Process stream items as they arrive:Runtime Interaction
Tasks can interact with the Iced runtime:Window Operations
Widget Operations
Clipboard Operations
Task Composition Example
Here’s a complete example showing task composition:Best Practices
Use Task::none() for synchronous updates
Use Task::none() for synchronous updates
When your update doesn’t need to perform any async work, return
Task::none() instead of creating unnecessary tasks.Batch independent tasks
Batch independent tasks
Use
Task::batch() to run multiple independent async operations concurrently rather than chaining them sequentially.Make tasks abortable for long operations
Make tasks abortable for long operations
For long-running operations like downloads or network requests, use
.abortable() and store the handle so users can cancel them.Use Task::map for composability
Use Task::map for composability
When working with nested components, use
.map() to transform child messages to parent messages for better composition.Next Steps
Subscriptions
Learn about passive data sources
Architecture
Understand the application architecture
