1
0
mirror of https://gitcode.com/gh_mirrors/re/react-native-pushy.git synced 2025-10-07 12:25:13 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee

immediate reject

This commit is contained in:
sunnylqm
2020-01-19 00:13:50 +08:00
parent c46fb1be3a
commit c28eec436d

View File

@@ -1,6 +1,6 @@
let availableDomain = 'update.reactnative.cn';
function ping(domain) {
function ping(domain, rejectImmediate) {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = e => {
@@ -10,7 +10,7 @@ function ping(domain) {
if (xhr.status === 200) {
resolve(domain);
} else {
setTimeout(reject, 5000);
rejectImmediate ? reject() : setTimeout(reject, 5000);
}
};
xhr.open('HEAD', `https://${domain}`);
@@ -26,7 +26,7 @@ function logger(...args) {
export async function tryBackupDomains() {
try {
await ping(availableDomain);
await ping(availableDomain, true);
logger('main domain ok');
return;
} catch (e) {