From 6713f2d4aa510b2f944665a95b9cdd9a5c7474b2 Mon Sep 17 00:00:00 2001 From: Jaimin Panchal Date: Fri, 13 Oct 2017 15:06:32 -0400 Subject: [PATCH] calling adapter after all bidrequests are pushed to pbjs._bidsRequested. fixes https://github.com/prebid/Prebid.js/issues/1603 --- src/adaptermanager.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/adaptermanager.js b/src/adaptermanager.js index 48c320548a0..e300956682d 100644 --- a/src/adaptermanager.js +++ b/src/adaptermanager.js @@ -156,6 +156,7 @@ exports.callBids = ({adUnits, cbTimeout}) => { } } + let _bidderRequests = []; bidderCodes.forEach(bidderCode => { const adapter = _bidderRegistry[bidderCode]; if (adapter) { @@ -165,20 +166,29 @@ exports.callBids = ({adUnits, cbTimeout}) => { requestId, bidderRequestId, bids: getBids({bidderCode, requestId, bidderRequestId, adUnits}), - start: new Date().getTime(), auctionStart: auctionStart, timeout: cbTimeout }; if (bidderRequest.bids && bidderRequest.bids.length !== 0) { - utils.logMessage(`CALLING BIDDER ======= ${bidderCode}`); $$PREBID_GLOBAL$$._bidsRequested.push(bidderRequest); - events.emit(CONSTANTS.EVENTS.BID_REQUESTED, bidderRequest); - adapter.callBids(bidderRequest); + _bidderRequests.push(bidderRequest); } - } else { - utils.logError(`Adapter trying to be called which does not exist: ${bidderCode} adaptermanager.callBids`); } }); + + _bidderRequests.forEach(bidRequest => { + bidRequest.start = new Date().getTime(); + const adapter = _bidderRegistry[bidRequest.bidderCode]; + if (adapter) { + if (bidRequest.bids && bidRequest.bids.length !== 0) { + utils.logMessage(`CALLING BIDDER ======= ${bidRequest.bidderCode}`); + events.emit(CONSTANTS.EVENTS.BID_REQUESTED, bidRequest); + adapter.callBids(bidRequest); + } + } else { + utils.logError(`Adapter trying to be called which does not exist: ${bidRequest.bidderCode} adaptermanager.callBids`); + } + }) }; function transformHeightWidth(adUnit) {