Function async_blocking_stdio::stdout
source ยท pub fn stdout() -> StdoutUnblock
Expand description
Get the synchronised blocking::Unblock
-ed stdout. A best-effort attempt is made to flush
the asynchronous standard output upon program exit (including things stored in the pipe it uses
to do async things).
The returned handle cannot be locked in a re-entrant fashion while the lock is held, within a future/task that is being waited for. If you try, it will cause a deadlock.
Examples found in repository?
More examples
examples/helloworld-re-syncify.rs (line 9)
6 7 8 9 10 11 12 13 14 15 16 17 18
fn main() -> std::io::Result<()> {
futures_lite::future::block_on(async {
use std::io::Write;
let mut stdout_sync_handle = astdio::stdout().lock_into_sync().await;
// Note how we do not need to bother flushing this - it's auto-handled by the crate, and is
// basically just println! here.
//
// However - in reality, this is not ideal because `BlockOn` uses
// futures_lite::future::block_on internally - it's better to use the async traits
// internally where possible if you're inside a future like this.
writeln!(stdout_sync_handle, "Hello world, from sync!")
})
}