[go: up one dir, main page]

Crate google_cloud_lro

Crate google_cloud_lro 

Source
Expand description

Types and functions to make LROs easier to use and to require less boilerplate.

Occasionally, a Google Cloud service may need to expose a method that takes a significant amount of time to complete. In these situations, it is often a poor user experience to simply block while the task runs. Such services return a long-running operation, a type of promise that can be polled until it completes successfully.

Polling these operations can be tedious. The application needs to periodically make RPCs, extract the result from the response, and may need to implement a stream to return metadata representing any progress in the RPC.

The Google Cloud client libraries for Rust return implementations of this trait to simplify working with these long-running operations.

§Example: automatically poll until completion

async fn start_lro() -> impl Poller<Response, Metadata> {
    // ... details omitted ...
}
let response = start_lro()
    .await
    .until_done()
    .await?;
println!("response = {response:?}");

§Example: poll with metadata


async fn start_lro() -> impl Poller<Response, Metadata> {
    // ... details omitted ...
}
let mut poller = start_lro().await;
while let Some(p) = poller.poll().await {
    match p {
        PollingResult::Completed(r) => { println!("LRO completed, response={r:?}"); }
        PollingResult::InProgress(m) => { println!("LRO in progress, metadata={m:?}"); }
        PollingResult::PollingError(e) => { println!("Transient error polling the LRO: {e}"); }
    }
    tokio::time::sleep(std::time::Duration::from_millis(100)).await;
}

Enums§

PollingResult
The result of polling a Long-Running Operation (LRO).

Traits§

Poller
Automatically polls long-running operations.