From 42e205129034ba9888a7273cf01e0bf91768c937 Mon Sep 17 00:00:00 2001 From: sunnylqm Date: Mon, 4 Mar 2024 12:30:00 +0800 Subject: [PATCH] fix: add timeout --- package.json | 2 +- src/utils.ts | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 9a7b400..475ae4b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-update", - "version": "10.2.1", + "version": "10.2.2", "description": "react-native hot update", "main": "src/index.ts", "scripts": { diff --git a/src/utils.ts b/src/utils.ts index 17b2fce..6651fde 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -9,10 +9,13 @@ export function assertRelease() { } const ping = async (url: string) => - fetch(url, { - method: 'HEAD', - redirect: 'follow', - }).then(({ status }) => status === 200); + Promise.race([ + fetch(url, { + method: 'HEAD', + redirect: 'follow', + }).then(({ status }) => status === 200), + new Promise((r) => setTimeout(() => r(false), 2000)), + ]); const canUseGoogle = ping('https://www.google.com');