I'm currently working on converting a sync project to async. One pattern I'm coming across a lot is where the library spawns threads to allow an mpsc receiver to run concurrently with the rest of the work being done. I'm trying to figure out the best way to accomplish this while still staying executor-agnostic. Here are the options i could think of, I'd love some input:
- I could just expose some new futures that do the same thing that the user could spawn on their own executor, but that would end up with a lot of new API and would be error-prone as there would be nothing preventing the user from forgetting to spawn those tasks.
- I could accept an object that implements
futures::task::Spawnand use that internally to spawn the tasks instead of spawning a new thread
- I could use conditional compilation that targets the 3 major executors and the user would just have to compile with the correct feature on
Am I missing any options? Is there a "best" way to do this? Thanks for all the help