2 releases

0.1.1 May 23, 2024
0.1.0 May 23, 2024

#483 in Asynchronous

MIT/Apache

8KB
55 lines

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");
}

Dependencies

~2.6–8.5MB
~63K SLoC