Monday 30 March 2020

Long-running process delaying promises

I have a process that runs for hours, and it has a callback every 1 percent, whose purpose is to send the new percent to the API so that the UI can track the progress.I know the callback is happening because I can see the percentage being console logged.But my promise to send out the new percentage to the API (using axios if that makes a difference) is delayed until the long-running process finishes. All 100 requests to my API go out at the same time, after the long process is completed.What can I do to ensure that my API request is actually sent out instantly, rather than delayed? Here's some pseudo code to clear up any potential confusion.longProcess.start({ onPercent: async percent => { console.log(percent); // I can see this at the right time (one every couple // minutes) await api.updatePercent(percent) console.log('done', percent) // All 100 of these get printed at the same // time. After the entire thing is done. } });

Submitted March 31, 2020 at 02:00AM by esreveReverse

No comments:

Post a Comment