What's best way to use indicatif progress bar with reqwest POST?

I want to add progress bar to my function (just async function to POST to a website)

let client = reqwest::Client::builder()
let post_resp = client

so If I increase my progress bar when making post data but they don't take much time only this post will block updating ETA time in the progress bar and quickly ends.

What I want to do is to make the progress bar more smoother overall (so far I tried like this

progress_bar.inc(30); // +30%
tokio::time::sleep(Duration::from_millis(12)).await; // artificial delay

I also thought about spawning background thread to update but idk what's best value for POST as i have to wait that loop to finish even thought POST is done.

let progress_task = tokio::spawn(async move {
            let mut i = 0;
            let mut intv = tokio::time::interval(Duration::from_millis(10));

            // Loop until progress is complete
            while i < 100 {
                i += 1;
                // cloned.set_position(i);

You can use an async_stream to split your upload into chunks, which also gives you breakpoints to update your progress bar.

Something like this:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.