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 and all messages from the commands will be collected and returned. This is useful when you need to perform multiple independent operations simultaneously.
§Arguments
cmds- A vector of commands to execute concurrently
§Returns
A command that executes all provided commands in parallel
§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()
}
}