Javascript promises. Continually repeat first promise until second promise resolves

So I’ve got a React App that creates a video, this is a very long api request taking between 1 and 10 minutes to resolve. I have a separate api call which I need to run continually every couple of seconds to check the status until the first promise is resolved (and the video is compiled).

        const promise1 ="/api/create", data);
        //promise1 takes between 1 and 10 minutes to resolve (video creation).

        const promise2 = axios.get(`/progress-${uniqueId}.txt`);
        // I need promise2 (which checks status of promise1) to continually run
        //at an interval (every 5 seconds?) until promise 1 resolves

        Promise.race([promise1, promise2]).then(res=>{
            //this obviously returns promise2 first, as expected, but 
            //once it comes back I need it to refire after 5 seconds
            //continually until promise 1 resolves

Any idea how I can recursively call Promise2 until Promise1 Resolves?

26 thoughts on “Javascript promises. Continually repeat first promise until second promise resolves”

  1. 394704 727159You are the most effective, Its posts like this that maintain me coming back and checking this internet site regularly, thanks for the info! 390416

  2. 264936 188298What a outstanding viewpoint, nonetheless is just not produce every sence by any indicates discussing this mather. Just about any technique thanks and also i had try and discuss your post directly into delicius but it surely appears to be an problem within your blogging is it possible you ought to recheck this. thank you just as before. 239077


Leave a Comment