Struct madsim::Handle[][src]

pub struct Handle {
    pub net: NetHandle,
    pub fs: FsHandle,
    // some fields omitted
}
Expand description

Supervisor handle to the runtime.

Fields

net: NetHandlefs: FsHandle

Implementations

Returns a Handle view over the currently running Runtime.

Panic

This will panic if called outside the context of a Madsim runtime.

let handle = madsim::Handle::current();

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.