Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
res = await retryInterval(retries, retryWait, async () => {
// the atom _will_ return, either because it finished or an error
// including a timeout error
if (await this.executeAtom('execute_script', [`return window.hasOwnProperty('${promiseName}Value');`, [null, null], subcommandTimeout], frames)) {
// we only put the property on `window` when the callback is called,
// so if it is there, everything is done
return await this.executeAtom('execute_script', [`return window.${promiseName}Value;`, [null, null], subcommandTimeout], frames);
}
// throw a TimeoutError, or else it needs to be caught and re-thrown
throw new errors.TimeoutError(`Timed out waiting for asynchronous script ` +
`result after ${timer.getDuration().asMilliSeconds.toFixed(0)}ms'));`);
});
} finally {
if (!timeout) {
return await proxy.command(endpoint, method, body);
}
log.debug(`Setting custom timeout to ${timeout} ms for '${cmdName}' command`);
let isCommandExpired = false;
const res = await B.resolve(proxy.command(endpoint, method, body))
.timeout(timeout)
.catch(B.Promise.TimeoutError, () => {
isCommandExpired = true;
});
if (isCommandExpired) {
proxy.cancelActiveRequests();
const errMsg = `Appium did not get any response from '${cmdName}' command in ${timeout} ms`;
await this.startUnexpectedShutdown(new errors.TimeoutError(errMsg));
log.errorAndThrow(errMsg);
}
return res;
};