1

I need to have currentFunction wait to return its request until baseUrl has executed.

The issue that I have is that adsRequest returns in currentFunction before baseUrl executes.

currentFunction function(){
...
     let base = []     

     function baseUrl(url){
        base.push(url)
      };

        pbjs.requestBids({
          timeout: 2000,
          //callback that executes when all the bid responses are back or the timeout hits
          //the callback receives two parameters
          bidsBackHandler : function(bids, timeout) {
            console.log(bids)
            console.log(timeout)
            var videoUrl = pbjs.adServers.dfp.buildVideoUrl({
              adUnit: videoAdUnit,
              params: {
                iu: '/188641797/video/test'
              }
            });
            baseUrl(videoUrl)
          }
        });
      });

     adsRequest.adTagUrl = `${base[0]}${targetingQueryParams}`;

     return adsRequest;
}
schoenbl
  • 663
  • 2
  • 14
  • 29
  • 1
    It could be helpful: [Using Promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises) – gcfabri Sep 12 '19 at 00:03
  • Yes I agree using a Promise would work. You can still use callbacks in this situation but you need to structure your currently callback/implementation differently. You might find yourself in callback hell as you add features to this code. – codedawi Sep 12 '19 at 00:19

0 Answers0