Skip to main content

MIGRATE_PATCH_DESCRIPTION

Constant MIGRATE_PATCH_DESCRIPTION 

Source
pub const MIGRATE_PATCH_DESCRIPTION: &str = "see doc comment above";
Expand description

Patch description for rpc_call_raw in lib.rs.

Replace the existing loop body:

// BEFORE: only FLOOD_WAIT handled:
async fn rpc_call_raw<R: RemoteCall>(&self, req: &R) -> Result<Vec<u8>, InvocationError> {
let mut fail_count   = NonZeroU32::new(1).unwrap();
let mut slept_so_far = Duration::default();
loop {
    match self.do_rpc_call(req).await {
        Ok(body) => return Ok(body),
        Err(e) => {
            let ctx = RetryContext { fail_count, slept_so_far, error: e };
            match self.inner.retry_policy.should_retry(&ctx) {
                ControlFlow::Continue(delay) => { sleep(delay).await; slept_so_far += delay; fail_count = fail_count.saturating_add(1); }
                ControlFlow::Break(())       => return Err(ctx.error),
            }
        }
    }
}
}

// AFTER: MIGRATE auto-handled, RetryLoop used:
async fn rpc_call_raw<R: RemoteCall>(&self, req: &R) -> Result<Vec<u8>, InvocationError> {
let mut rl = RetryLoop::new(Arc::clone(&self.inner.retry_policy));
loop {
    match self.do_rpc_call(req).await {
        Ok(body) => return Ok(body),
        Err(e) if let Some(dc_id) = e.migrate_dc_id() => {
            // Telegram is redirecting us to a different DC.
            // Migrate transparently and retry: no error surfaces to caller.
            self.migrate_to(dc_id).await?;
        }
        Err(e) => rl.advance(e).await?,
    }
}
}

With this change, the manual MIGRATE checks in bot_sign_in, request_login_code, and sign_in can be deleted.