pub fn batch(cmds: Vec<Cmd>) -> CmdExpand description
Creates a command that executes a batch of commands concurrently.
The commands in the batch will be executed in parallel immediately when this command is processed by the program. This is a non-blocking operation that spawns each command in its own task, allowing for smooth animations and responsive user interfaces.
§Arguments
cmds- A vector of commands to execute concurrently
§Returns
A command that immediately dispatches all provided commands for concurrent execution
§Examples
use bubbletea_rs::{command, Model, Msg};
use std::time::Duration;
struct MyModel;
impl Model for MyModel {
fn init() -> (Self, Option<command::Cmd>) {
let model = Self {};
// Execute multiple operations concurrently
let cmd = command::batch(vec![
command::window_size(), // Get window dimensions
command::tick(Duration::from_secs(1), |_| {
Box::new("InitialTickMsg") as Msg
}),
command::hide_cursor(), // Hide the cursor
]);
(model, Some(cmd))
}
fn update(&mut self, msg: Msg) -> Option<command::Cmd> {
None
}
fn view(&self) -> String {
"Loading...".to_string()
}
}