pub fn get_runtime_handle() -> Result<Handle, ArrErr>
Expand description

Get the tokio handle of the current runtime. Makes sure a Handle is returned, even if there is no current handle found. The handle can be used to spawn a separate task, or run an async function from a non-async function.

Examples

use svc_storage::grpc::get_runtime_handle;
use svc_storage::postgres::simple_resource::PsqlType;
use svc_storage::resources::base::ResourceObject;
use svc_storage::resources::vertipad;
async fn example() {
    let id = uuid::Uuid::new_v4();
    let handle = get_runtime_handle();
    // start a blocking task so we can make sure
    // our function is ready before we continue our code
    let data = tokio::task::block_in_place(move || {
        // use the tokio handle to block on our async function
        handle.expect("no handle").block_on(async move {
            // run async function
            <ResourceObject<vertipad::Data> as
            PsqlType>::get_by_id(&id).await
        })
    });
}