Crate tokio_shared

Source
Expand description

§tokio-shared-rs

Share a tokio Runtime between a dylib/cdylib and the main binary

Caution: multi-thread flavor is not supported yet

§Usage

[dependencies]
tokio-shared = "0.1"

checkout examples/example.rs

§dylib’s case

use tokio_shared::SharedTokioHandle;

fn main() {
    let handle = SharedTokioHandle::new();
    let _guard = example_lib::setup_shared_tokio_ref(&handle);
    example_lib::run("dylib");
}

§cdylib’s case

use tokio_shared::SharedTokioHandle;

fn main() {
    let dylib = unsafe { libloading::Library::new(dylib) }.expect("error loading dylib");
    let setup_tokio: FnSetupTokio = unsafe { *dylib.get(b"setup_shared_tokio_ref").unwrap() };
    let _guard = setup_tokio(&logger);
    let run: FnRun = unsafe { *dylib.get(b"run").unwrap() };
    run("cdylib");
}

Structs§

SharedTokioHandle
TokioEnterGuard

Functions§

setup_shared_tokio_ref