Skip to main content

run_blocking_with

Function run_blocking_with 

Source
pub fn run_blocking_with<B, A>(
    term: Terminal<B>,
    app: A,
    options: RunOptions,
) -> Result<(), B::Error>
where B: Backend, A: App<B>,
Expand description

Drive an App with a blocking loop until it returns Flow::Exit, paced by options.

The zero-config run_blocking is equivalent to run_blocking_with(term, app, RunOptions::default()). Pass RunOptions::animated for a continuously-rendering loop capped at a fixed rate instead, using a FrameClock internally so update is called at even intervals rather than however fast the host can spin.

With RunOptions::is_event_driven true (the default), Flow::Idle blocks the loop on input (via Terminal::wait_for_input) instead of calling update again immediately: an idle app has nothing new to show, so there is no reason to burn CPU polling it at all, let alone faster than any configured rate. With event_driven false, an idle loop still waits out the remainder of the current target_fps interval (if set) before calling update again, rather than looping immediately, but never blocks on input.

§Errors

Returns the backend’s error if the automatic present() call fails. The loop stops and the terminal is dropped (running backend teardown) before the error is returned.

§Panics

Panics if options.target_fps is Some(0): pacing at a FrameClock internally, which requires a non-zero rate (see FrameClock::new).