Encapsulating async

I'm using async out of necessity because we have a gRPC client.

What is the best way to encapsulate async so that it does not become viral throughout the entire code base? Obviously this means not calling await as that's only possible in async functions.

Must I poll the resultant Futures manually?

You will need to call the async code from sync code at some point:

use tokio::runtime::Runtime;

// Create the runtime
let rt  = Runtime::new().unwrap();

// Execute the future, blocking the current thread until completion
rt.block_on(async {
    // Your async code here
});
1 Like

Great reference:

1 Like