Struct madsim::Handle [−][src]
Expand description
Supervisor handle to the runtime.
Fields
net: NetHandle
fs: FsHandle
Implementations
Kill a host.
- All tasks spawned on this host will be killed immediately.
- All data that has not been flushed to the disk will be lost.
Example
use madsim::{Runtime, time::{sleep, Duration}};
use std::sync::{Arc, atomic::{AtomicUsize, Ordering}};
let rt = Runtime::new();
let addr = "0.0.0.1:1".parse().unwrap();
// host increases the counter every 2s
let flag = Arc::new(AtomicUsize::new(0));
let flag_ = flag.clone();
rt.local_handle(addr).spawn(async move {
loop {
sleep(Duration::from_secs(2)).await;
flag_.fetch_add(2, Ordering::SeqCst);
}
}).detach();
let handle = rt.handle();
rt.block_on(async move {
sleep(Duration::from_secs(3)).await;
assert_eq!(flag.load(Ordering::SeqCst), 2);
handle.kill(addr);
sleep(Duration::from_secs(2)).await;
assert_eq!(flag.load(Ordering::SeqCst), 2);
});
Return a handle of the specified host.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Handle
impl !UnwindSafe for Handle
Blanket Implementations
Mutably borrows from an owned value. Read more