Anonymous user
Events: Difference between revisions
Add Rust implementation
(Add Rust implementation) |
|||
Line 1,072:
════════════ program halted.
</pre>
=={{header|Rust}}==
Rust ensures memory safety at compile-time without needing a garbage collector or runtime. There are several concurrency primitives in it's standard library.
<lang Rust>
use std::{sync::mpsc, thread, time::Duration};
fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("[1] Starting");
let (tx, rx) = mpsc::channel();
thread::spawn(move || {
println!("[2] Waiting for event");
rx.recv();
println!("[2] Received event");
});
thread::sleep(Duration::from_secs(1));
println!("[1] Sending event");
tx.send(())?;
thread::sleep(Duration::from_secs(1));
Ok(())
}
</lang>
=={{header|Tcl}}==
|