I was following Michael-F-Bryan's Dynamic Loading & Plugins chapter from his Rust FFI guide, but I am storing the plugins in a HashMap (HashMap<&'static str, Box<dyn Plugin>) instead of a Vec so that I can call the functions of a Plugin individually.
I would like the plugins to define a asynchronous function with it's own loop that communicates with the main part of the application using channels (std or tokio).
Working around the fact that you can't have async functions in traits was easy thanks to the async_trait crate, but the issue that I am now facing is, that I cannot spawn a new thread with the module because the new thread might outlive the PluginManager.
I tried to recreate this in a rust playground without the dynamic modules and I'm facing the same error here (note: this does not include any kind of channel communication)
Unlike the first error, I was unable to recreate a rust playground for the second one (as it happens at runtime). Instead of spawning a new thread, I was using tokio's event loop to handle the async functions. This works in the sandbox, but not when using a shared library as plugin. At runtime it throws:
thread '<unnamed>' panicked at 'there is no timer running, must be called from the context of Tokio runtime', /home/admin/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.0.1/src/time/driver/handle.rs:50:18
If someone knows a solution around this problem, or even had the same issue, it would be great if you could share them with me as I've already tried so much but nothing worked in my favor.