Function spawn_stdin_stream

Source
pub fn spawn_stdin_stream() -> Receiver<String>
Expand description

Spawns a background thread that continuously reads from stdin as a stream.

This function returns an mpsc Receiver, allowing non-blocking polling of stdin input just like spawn_stdin_channel.

§Returns

A Receiver<String> that emits lines from stdin.

§Example

use stdin_nonblocking::spawn_stdin_stream;
use std::sync::mpsc::TryRecvError;
use std::time::Duration;

let stdin_stream = spawn_stdin_stream();

loop {
    match stdin_stream.try_recv() {
        Ok(line) => println!("Received: {}", line),
        Err(TryRecvError::Empty) => {
            // No input yet; continue execution
        }
        Err(TryRecvError::Disconnected) => {
            println!("Input stream closed. Exiting...");
            break;
        }
    }
    std::thread::sleep(Duration::from_millis(500));
}