Since there is not much work between random api calls idea is to call them concurrently, wait for the result, and in the meantime thread go back to do something else and check back again.
What is the best way to implement this in Rust? Following is experimental code but call does not complete in the background.
I cannot use join all as rest calls are made on random occurring events. Ideally just post the call and check the future later for data.
I know almost nothing about async/await or tokio in Rust and have never tried to use them but from the documentation I read:
"This function [run_until_stalled] will not block the calling thread and will return the moment that there are no tasks left for which progress can be made; remaining incomplete tasks in the pool can continue with further use of one of the pool's run or poll methods. While the function is running, all tasks in the pool will try to make progress."
That hints to me that you have "remaining incomplete tasks" so you are not getting the result you want and that you should loop on run_until_stalled() until all the work is actually done.
Your 10 second sleep does not help. During that time none of your async stuff can make progress, you are not running it. And you have blocked your thread anyway so nothing is happening. There is no "background".
I just don't see how we can expect the async engine to run and handle the events required to get the job done if we are not actually running said async engine.
I don't know, I'll be interested to see what anyone suggests.