Crates.io | tokio-shared |
lib.rs | tokio-shared |
version | 0.1.1 |
source | src |
created_at | 2024-05-23 12:03:03.615542 |
updated_at | 2024-05-23 13:14:20.420707 |
description | Share tokio Runtime bwtween dylibs |
homepage | |
repository | https://github.com/JakkuSakura/tokio-shared-rs |
max_upload_size | |
id | 1249419 |
size | 21,103 |
Share a tokio Runtime between a dylib/cdylib and the main binary
Caution: multi-thread flavor is not supported yet
[dependencies]
tokio-shared = "0.1"
checkout examples/example.rs
use tokio_shared::SharedTokioHandle;
fn main() {
let handle = SharedTokioHandle::new();
let _guard = example_lib::setup_shared_tokio_ref(&handle);
example_lib::run("dylib");
}
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");
}