So I'm having a own library that I use to spawn threads and have a thread pool, mainly because I need strictly specific actions on delegating tasks and when the program is closing. Recently I implemented into most of my methods Tokio crate so I got to a point at which I had to implement async/await into the closures that were being sent for execution over to the thread pool. Unfortunately I can't quite figure out how to properly use both and I even started to think that I should go with one of the two (since the default runtime on Tokio is spawning tasks on different threads if I remember correct).
What I tried:
- I tried
executor::LocalPool::new().run_until()on the received closure in the pool, but that's panicking the spawned thread with "
executor from within another executor: EnterError" (are spawned threads copying the fn main() of the main thread and that's why they already have an executor?)
- I tried changing the thread pool to accept
Box<Future<...> + Send>and also return a
Box<Future<...> + Send>that would be executed on thread spawn so we can spin the thread. The problem here is with the closure, it doesn't implement Unpin so it can't be moved. I've not been able to figure out a different approach how to accept DST (dyn Future<...>) and return such while covering it behind a moveable allocated memory.
Am I thinking all of this the wrong way? Any guides/documentation would be appreciated.