Expand description
The main Program struct that runs the application
§Async Task Spawning Methods
The Program struct provides several methods for spawning async tasks, each optimized for different use cases:
§commands::spawn() - Simple Async Task Spawning
- Purpose: Simple fire-and-forget async operations
- Use cases: HTTP requests, file I/O, simple background work
- Lifecycle: Runs to completion, sends optional result message
- Cancellation: No built-in cancellation support
- Example: One-time data fetch, file save operation
§Program::spawn() - Runtime-Managed Task Spawning
- Purpose: Tasks that need to communicate with the running program
- Use cases: Background tasks that send multiple messages
- Lifecycle: Managed by program runtime, automatic cleanup
- Cancellation: No built-in cancellation support
- Example: Background data processing that sends progress updates
§Program::spawn_cancellable() - Cancellable Task Handles
- Purpose: Long-running tasks that may need to be cancelled
- Use cases: User-cancellable operations, background monitors
- Lifecycle: Returns AsyncHandle for manual cancellation
- Cancellation: Cooperative cancellation via CancellationToken
- Example: File upload/download, long-running computation
§Program::spawn_cancellable_cmd() - Cancellable Message-Sending Tasks
- Purpose: Long-running tasks that send messages AND can be cancelled
- Use cases: Real-time data streams, periodic background tasks
- Lifecycle: Returns AsyncHandle, integrated with message passing
- Cancellation: Cooperative cancellation via CancellationToken
- Example: Live data feeds, periodic health checks
§Choosing the Right Method
ⓘ
// Simple one-shot operation
let cmd = commands::spawn(async {
let data = fetch_data().await;
Some(Msg::DataLoaded(data))
});
// Background task with progress updates
program.spawn(async {
process_large_file().await;
Some(Msg::ProcessingComplete)
});
// User-cancellable operation
let handle = program.spawn_cancellable(|token| async move {
expensive_computation(token).await
});
// Real-time stream with cancellation
let handle = program.spawn_cancellable_cmd(|token, sender| async move {
while !token.is_cancelled() {
let data = stream.next().await;
sender.send(Event::User(Msg::StreamData(data)));
}
});Modules§
- error_
handler - Error handling utilities for the runtime
Structs§
- Command
Executor - Executes commands and sends resulting messages
- Event
Processor - Processes raw crossterm events into hojicha events
- Event
Stats - Statistics for monitoring event processing behavior
- FpsLimiter
- Controls the frame rate of rendering
- Priority
Config - Configuration for priority event processing
- Priority
Event Processor - Priority-aware event processor
- Program
- The main program that runs your application
- Program
Options - Options for configuring the program
- Terminal
Config - Configuration for terminal setup
- Terminal
Manager - Manages terminal setup, teardown, and state
Enums§
- Mouse
Mode - Mouse tracking mode
Functions§
- get_
event_ stats - Public API for getting event processing statistics