/// Poll for token, bail after 500 seconds.
Poll for token, bail after 500 seconds.
Poll for token bail after 500 seconds .
fn poll_token(token_id: String) -> Result<String> {
    let mut request_params = HashMap::new();
    request_params.insert("token-id", token_id);
    let client = reqwest::blocking::Client::builder().build()?;
    let timer = Timer::new().interval_ms(1000).iter();
    let style = ProgressStyle::default_spinner().template("{spinner}   {msg}");
    let spinner = ProgressBar::new_spinner().with_style(style);
    spinner.set_message("Waiting for API token...");
    spinner.enable_steady_tick(20);
    for (seconds, _) in timer.enumerate() {
        let res = client
            .get("https://api.cloudflare.com/client/v4/workers/token")
            .json(&request_params)
            .send()?;
        if res.status().is_success() {
            let body: TokenResponse = res.json()?;
            return Ok(body.result);
        }
        if seconds >= 500 {
            break;
        }
    }
    anyhow::bail!(
        "Timed out while waiting for API token. Try using `wrangler config` if login fails to work."
    );
}
fn poll_token ( token_id : String ) -> Result < String > { let mut request_params = HashMap :: new ( ) ; request_params . insert ( " " , token_id ) ; let client = reqwest :: blocking :: Client :: builder ( ) . build ( ) ? ; let timer = Timer :: new ( ) . interval_ms ( 1000 ) . iter ( ) ; let style = ProgressStyle :: default_spinner ( ) . template ( " " ) ; let spinner = ProgressBar :: new_spinner ( ) . with_style ( style ) ; spinner . set_message ( " " ) ; spinner . enable_steady_tick ( 20 ) ; for ( seconds , _ ) in timer . enumerate ( ) { let res = client . get ( " " ) . json ( & request_params ) . send ( ) ? ; if res . status ( ) . is_success ( ) { let body : TokenResponse = res . json ( ) ? ; return Ok ( body . result ) ; } if seconds >= 500 { break ; } } anyhow :: bail ! ( " " ) ; }
Poll for token, bail after 500 seconds.
Poll for token bail after 500 seconds .
token_id
String