Skip to content

Commit 9dc0348

Browse files
Matt Kendalldluxemburg
Matt Kendall
authored andcommitted
Improvement/timeout xhr (prebid#1172)
* implement timeout on ajax requests * missing semi-colon
1 parent 6fa2aa4 commit 9dc0348

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/ajax.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {parse as parseURL, format as formatURL} from './url';
33
var utils = require('./utils');
44

55
const XHR_DONE = 4;
6+
let _timeout = 3000;
67

78
/**
89
* Simple IE9+ and cross-browser ajax request function
@@ -13,6 +14,9 @@ const XHR_DONE = 4;
1314
* @param data mixed data
1415
* @param options object
1516
*/
17+
export function setAjaxTimeout(timeout) {
18+
_timeout = timeout;
19+
}
1620

1721
export function ajax(url, callback, data, options = {}) {
1822
try {
@@ -42,6 +46,7 @@ export function ajax(url, callback, data, options = {}) {
4246
}
4347
}
4448

49+
x.timeout = _timeout;
4550
if (useXDomainRequest) {
4651
x = new window.XDomainRequest();
4752
x.onload = function () {

src/prebid.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { isValidePriceConfig } from './cpmBucketManager';
1010
import { listenMessagesFromCreative } from './secureCreatives';
1111
import { syncCookies } from 'src/cookie.js';
1212
import { loadScript } from './adloader';
13+
import { setAjaxTimeout } from './ajax';
1314

1415

1516
var $$PREBID_GLOBAL$$ = getGlobal();
@@ -455,6 +456,7 @@ $$PREBID_GLOBAL$$.requestBids = function ({ bidsBackHandler, timeout, adUnits, a
455456
const timedOut = true;
456457
const timeoutCallback = bidmanager.executeCallback.bind(bidmanager, timedOut);
457458
const timer = setTimeout(timeoutCallback, cbTimeout);
459+
setAjaxTimeout(cbTimeout);
458460
if (typeof bidsBackHandler === objectType_function) {
459461
bidmanager.addOneTimeCallback(bidsBackHandler, timer);
460462
}

0 commit comments

Comments
 (0)