cannot find what is causing the race condition or deadlock

This commit is contained in:
lever1209 2024-08-20 15:51:01 -03:00
commit 9a86073066
No known key found for this signature in database
GPG key ID: 0EA7B9E85212693C
8 changed files with 199 additions and 259 deletions

View 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"

View 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
})
}