I didn’t quite understand this point. IIUC, you are saying that if await was explicit, you would have tried to await!(pika_client()) and gotten an error that pika_client is not async. Is that correct?
Sorry, I didn’t quite understand the distinction between block_on and await.
To be clear, the actual work of do_work does not start until the select, right? So if I wanted to start the work earlier and concurrently do some other computation I would do something like this:
async fn do_work() { .. } // assume the work happens on thread B
async fn do_work_with_timeout() {
let work = async { do_work() };
let work = async { futures::await(work) }; // concurrently start `work` on B
my_sync_function(); // do some computation synchronously on this thread
let when = Instant::now() + Duration::from_millis(100);
let timeout = Delay::new(when);
futures::select(work, timeout);
}
Is that correct?
Is this supposed to say in a sync context (i.e. not in an async block/fn/closure)? Or does it intentionally mean that in an async context we will block until the Future is resolved?
I still don’t completely buy this argument. I realize that it’s possible for a function to do arbitrary crazy stuff in theory, but in practice I don’t usually expect a function to do arbitrary stuff in the middle without that being documented. On the other hand, in concurrent code I very much expect random stuff to happen in the middle of a function call (say, on another thread).