pub async fn next(&mut self) -> Result<Option<Vec<u8>>, InvocationError> {
        if self.done {
            return Ok(None);
        }

        use tl::enums::upload::File;

        // TODO handle FILE_MIGRATE and maybe FILEREF_UPGRADE_NEEDED
        let mut retries = 0;
        loop {
            break match self.client.invoke(&self.request).await {
                Ok(File::File(f)) => {
                    if f.bytes.len() < self.request.limit as usize {
                        self.done = true;
                        if f.bytes.is_empty() {
                            return Ok(None);
                        }
                    }

                    self.request.offset += self.request.limit;
                    Ok(Some(f.bytes))
                }
                Ok(File::CdnRedirect(_)) => {
                    panic!("API returned File::CdnRedirect even though cdn_supported = false");
                }
                // Rate limit hit
                Err(InvocationError::Rpc(err))
                    if err.code == 420 && retries < RATE_LIMIT_RETRIES =>
                {
                    tokio::time::sleep(RATE_LIMIT_DELAY).await;
                    retries += 1;
                    continue;
                }
                Err(e) => Err(e),
            };
        }
    }
/// Fetch and return the next chunk.
Fetch and return the next chunk.
Fetch and return the next chunk .
pub async fn next(&mut self) -> Result<Option<Vec<u8>>, InvocationError> {
        if self.done {
            return Ok(None);
        }
        use tl::enums::upload::File;
        // TODO handle FILE_MIGRATE and maybe FILEREF_UPGRADE_NEEDED
        let mut retries = 0;
        loop {
            break match self.client.invoke(&self.request).await {
                Ok(File::File(f)) => {
                    if f.bytes.len() < self.request.limit as usize {
                        self.done = true;
                        if f.bytes.is_empty() {
                            return Ok(None);
                        }
                    }
                    self.request.offset += self.request.limit;
                    Ok(Some(f.bytes))
                }
                Ok(File::CdnRedirect(_)) => {
                    panic!("API returned File::CdnRedirect even though cdn_supported = false");
                }
                // Rate limit hit
                Err(InvocationError::Rpc(err))
                    if err.code == 420 && retries < RATE_LIMIT_RETRIES =>
                {
                    tokio::time::sleep(RATE_LIMIT_DELAY).await;
                    retries += 1;
                    continue;
                }
                Err(e) => Err(e),
            };
        }
    }
pub async fn next ( & mut self ) -> Result < Option < Vec < u8 > > , InvocationError > { if self . done { return Ok ( None ) ; } use tl :: enums :: upload :: File ; // TODO handle FILE_MIGRATE and maybe FILEREF_UPGRADE_NEEDED let mut retries = 0 ; loop { break match self . client . invoke ( & self . request ) . await { Ok ( File :: File ( f ) ) => { if f . bytes . len ( ) < self . request . limit as usize { self . done = true ; if f . bytes . is_empty ( ) { return Ok ( None ) ; } } self . request . offset += self . request . limit ; Ok ( Some ( f . bytes ) ) } Ok ( File :: CdnRedirect ( _ ) ) => { panic ! ( " " ) ; } // Rate limit hit Err ( InvocationError :: Rpc ( err ) ) if err . code == 420 && retries < RATE_LIMIT_RETRIES => { tokio :: time :: sleep ( RATE_LIMIT_DELAY ) . await ; retries += 1 ; continue ; } Err ( e ) => Err ( e ) , } ; } }
Fetch and return the next chunk.
Fetch and return the next chunk .
&mut self
&mut self