[−][src]Function minus::tokio_updating
pub async fn tokio_updating(mutex: Lines)
Run the pager inside a tokio task
This function is only available when tokio_lib
feature is enabled
It takes a Lines
and updates the page with new information when Lines
is updated
This function switches to the Alternate Screen
of the TTY and
switches to raw mode
Example
use std::sync::{Arc, Mutex}; use futures::join; use std::fmt::Write; use std::time::Duration; use tokio::time::sleep; #[tokio::main] async fn main() { let output = Arc::new(Mutex::new(String::new())); let push_data = async { for i in 1..=100 { let mut guard = output.lock().unwrap(); // Always use writeln to add a \n after the line writeln!(guard, "{}", i); // If you have furthur asynchronous blocking code, drop the borrow here drop(guard); // Some asynchronous blocking code sleep(Duration::new(1,0)).await; } }; join!(minus::tokio_updating(output.clone()), push_data); }
Please do note that you should never lock the output data, since this will cause the paging thread to be paused. Only borrow it when it is required and drop it if you have furthur asynchronous blocking code