I have below method in JS where I do server call from a click of a button, now the requirement is to display percentage while waiting for promise object and to do the same currently I am increasing this.progress property 400 ms, I know this is not a good approach because it is not sure how much time a promise object will take to return value sometimes progress value is in the middle and promise returns value and sometimes progress reached at 100 and still waiting for promise object to finish

sendDatatoApex () {
    this._interval = setInterval(() => {
            this.progress = this.progress >= 96 ? 100 : this.progress + 2;
        }, 400);
        parma1: this.parm
    .then(result => {
        console.log('result ===> ' + result);

In real time I am using lightning spinner along with percentage, I have written CSS to display both of them together. Can anyone please suggest the right approach to display progress value on page while waiting for promise object to finish


There are no SLAs on how long any request to the org takes, which means you simply cannot count percentage progress by time. The imperative call could take 0.1 seconds or 10 seconds simply depending on the load on the physical servers running your org along with all the other orgs that are multi-tenanted on it too.

The only suggestion I have is to refactor your imperative code to perform small parts of the job it currently does, in a deterministic way (so you know how many times you will need to call the function [perhaps something you can calculate before starting the sequence]) and to invoke it repeatedly in a chained manner (to avoid boxcarring). Each time a partial execution completes you can then update the percentage for display.

  • is there way to turn off boxcarring as of 2020? Thanks.
    – Atlas Can
    Mar 27 '20 at 8:19
  • 1
    No, not for LWC, just to work around it as covered in the referenced answer. Visualforce has a mechanism for turning it off though. Can't remember about Aura.
    – Phil W
    Mar 27 '20 at 8:47
  • Aura has setBackground (see docs), and in LWC, boxcarring only happens if there's more than 5 requests, otherwise each request gets its own thread. Regardless, calling in a async loop would suffice.
    – sfdcfox
    Mar 27 '20 at 10:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.