Skip to content
This repository was archived by the owner on Jan 31, 2025. It is now read-only.

Commit 065b143

Browse files
author
Daniel Brain
committed
Use -1 universally for disabled timeout
1 parent 99d668b commit 065b143

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

src/conf/config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export let CONFIG : Object = {
1414
CHILD_WINDOW_TIMEOUT: 5000,
1515

1616
ACK_TIMEOUT: (window.navigator.userAgent.match(/MSIE/i) !== -1 && !__TEST__) ? 2000 : 1000,
17-
RES_TIMEOUT: __TEST__ ? 2000 : Infinity,
17+
RES_TIMEOUT: __TEST__ ? 2000 : -1,
1818

1919
LOG_TO_PAGE: false,
2020

src/lib/ready.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function onHello(handler : ({ source? : CrossDomainWindowType, origin? :
1919
}
2020

2121
export function sayHello(win : CrossDomainWindowType) : ZalgoPromise<{ origin : string }> {
22-
return global.send(win, CONSTANTS.POST_MESSAGE_NAMES.HELLO, {}, { domain: CONSTANTS.WILDCARD, timeout: Infinity })
22+
return global.send(win, CONSTANTS.POST_MESSAGE_NAMES.HELLO, {}, { domain: CONSTANTS.WILDCARD, timeout: -1 })
2323
.then(({ origin }) => {
2424
return { origin };
2525
});

src/lib/serialize.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export function deserializeMethod(source : CrossDomainWindowType, origin : strin
159159
name: obj.__name__,
160160
args
161161

162-
}, { domain: origin, timeout: Infinity }).then(({ data }) => {
162+
}, { domain: origin, timeout: -1 }).then(({ data }) => {
163163

164164
log.debug('Got foreign method result', obj.__name__, data.result);
165165
return data.result;

src/public/client.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -186,23 +186,25 @@ export function request(options : RequestOptionsType) : ZalgoPromise<ResponseMes
186186
return reject(new Error(`Window closed for ${ name } before response`));
187187
}
188188

189-
ackTimeout -= cycleTime;
190-
resTimeout -= cycleTime;
189+
ackTimeout = Math.max(ackTimeout - cycleTime, 0);
190+
if (resTimeout !== -1) {
191+
resTimeout = Math.max(resTimeout - cycleTime, 0);
192+
}
191193

192194
let hasAck = responseListener.ack;
193195

194196
if (hasAck) {
195197

196-
if (resTimeout === Infinity) {
198+
if (resTimeout === -1) {
197199
return;
198200
}
199201

200202
cycleTime = Math.min(resTimeout, 2000);
201203

202-
} else if (ackTimeout <= 0) {
204+
} else if (ackTimeout === 0) {
203205
return reject(new Error(`No ack for postMessage ${ name } in ${ getDomain() } in ${ CONFIG.ACK_TIMEOUT }ms`));
204206

205-
} else if (resTimeout <= 0) {
207+
} else if (resTimeout === 0) {
206208
return reject(new Error(`No response for postMessage ${ name } in ${ getDomain() } in ${ options.timeout || CONFIG.RES_TIMEOUT }ms`));
207209
}
208210

0 commit comments

Comments
 (0)