tokio-shared

Crates.iotokio-shared
lib.rstokio-shared
version0.1.1
sourcesrc
created_at2024-05-23 12:03:03.615542
updated_at2024-05-23 13:14:20.420707
descriptionShare tokio Runtime bwtween dylibs
homepage
repositoryhttps://github.com/JakkuSakura/tokio-shared-rs
max_upload_size
id1249419
size21,103
Jakku Sakura (JakkuSakura)

documentation

README

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");
}
Commit count: 2

cargo fmt