Canop / bacon

background rust code check
https://dystroy.org/bacon
GNU Affero General Public License v3.0
1.78k stars 62 forks source link

Inconsistent stdout flushing when using `bacon run` #185

Open jasondyoungberg opened 5 months ago

jasondyoungberg commented 5 months ago

When executing a Rust program using the bacon run command for the first time, the standard output is flushed on every newline. However, on subsequent runs, flushing appears to occur only upon program termination rather than as expected — every time the program itself issues a flush.

Expected Behavior

The expectation is for bacon run to flush the output consistently, in alignment with the behavior of my Rust program, which flushes after each output operation.

Current Behavior

Steps to Reproduce

  1. Use the following Rust code snippet:

    use std::{
        io::{stdout, Write},
        thread::sleep,
        time::Duration,
    };
    
    fn main() {
        for i in 0..10 {
            print!("\n{i}: ");
            for j in 0..10 {
                print!("{j} ");
                stdout().flush().unwrap();
                sleep(Duration::from_millis(100));
            }
        }
    }
  2. Run the program using cargo run to observe the expected behavior where every number is printed sequentially.

  3. Execute the program using bacon run to note the difference: only every line is printed during execution.

  4. On automatic execution upon save, observe that the output is displayed wholly at the end.

Environment