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

fix: avoid double check when init

This commit is contained in:
sunnylqm
2024-03-07 18:09:55 +08:00
parent 2bdc64ba1b
commit f655a1d954

View File

@@ -38,7 +38,7 @@ export class Pushy {
}; };
lastChecking: number; lastChecking: number;
lastResult: CheckResult; lastRespJson?: Promise<any>;
progressHandlers: Record<string, EmitterSubscription> = {}; progressHandlers: Record<string, EmitterSubscription> = {};
downloadedHash: string; downloadedHash: string;
@@ -139,11 +139,11 @@ export class Pushy {
assertRelease(); assertRelease();
const now = Date.now(); const now = Date.now();
if ( if (
this.lastResult && this.lastRespJson &&
this.lastChecking && this.lastChecking &&
now - this.lastChecking < 1000 * 5 now - this.lastChecking < 1000 * 5
) { ) {
return this.lastResult; return await this.lastRespJson;
} }
this.lastChecking = now; this.lastChecking = now;
this.report({ type: 'checking' }); this.report({ type: 'checking' });
@@ -184,11 +184,11 @@ export class Pushy {
type: 'errorChecking', type: 'errorChecking',
message: 'Can not connect to update server. Please check your network.', message: 'Can not connect to update server. Please check your network.',
}); });
return this.lastResult || empty; return this.lastRespJson ? await this.lastRespJson : empty;
} }
const result: CheckResult = await resp.json(); this.lastRespJson = resp.json();
this.lastResult = result; const result: CheckResult = await this.lastRespJson;
if (resp.status !== 200) { if (resp.status !== 200) {
this.report({ this.report({