cannot find what is causing the race condition or deadlock
This commit is contained in:
parent
a3b46410e8
commit
9a86073066
8 changed files with 199 additions and 259 deletions
14
plugins/testing/Cargo.toml
Normal file
14
plugins/testing/Cargo.toml
Normal file
|
@ -0,0 +1,14 @@
|
|||
[package]
|
||||
name = "testing"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
tokio = "1.39.3"
|
||||
tracing = "0.1.40"
|
||||
gpt-sandbox = { path = "../../" }
|
||||
async-trait = "0.1.81"
|
||||
once_cell = "1.19.0"
|
34
plugins/testing/src/lib.rs
Normal file
34
plugins/testing/src/lib.rs
Normal file
|
@ -0,0 +1,34 @@
|
|||
use async_trait::async_trait;
|
||||
use gpt_sandbox::{AsyncFn, Plugin, PluginResult, RegisterFn};
|
||||
use std::collections::HashMap;
|
||||
use tokio::runtime::Handle;
|
||||
|
||||
#[allow(improper_ctypes_definitions)] // will never be used by c programs, would use rust dylib if it existed
|
||||
#[no_mangle]
|
||||
pub extern "C" fn register_plugin() -> RegisterFn {
|
||||
Box::into_raw(Box::new(ExamplePlugin))
|
||||
}
|
||||
|
||||
struct ExamplePlugin;
|
||||
|
||||
#[async_trait]
|
||||
impl Plugin for ExamplePlugin {
|
||||
fn register_functions(&self) -> HashMap<String, AsyncFn> {
|
||||
let mut map = HashMap::new();
|
||||
map.insert("example_function".to_string(), example_function as AsyncFn);
|
||||
dbg!(map)
|
||||
}
|
||||
|
||||
fn unregister_functions(&self) -> Vec<String> {
|
||||
dbg!(vec!["example_function".to_string()])
|
||||
}
|
||||
}
|
||||
|
||||
fn example_function(handle: Handle) -> tokio::task::JoinHandle<PluginResult> {
|
||||
println!("start of example_function");
|
||||
|
||||
handle.spawn(async {
|
||||
println!("task running");
|
||||
PluginResult::Ok
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue