MCPcopy Index your code
hub / github.com/reactnativecn/react-native-update / fetchWithTimeout

Function fetchWithTimeout

src/utils.ts:116–136  ·  view source on GitHub ↗
(
  url: string,
  params: Parameters<typeof fetch>[1],
  timeoutMs = DEFAULT_FETCH_TIMEOUT_MS,
)

Source from the content-addressed store, hash-verified

114 : 0;
115
116export const fetchWithTimeout = (
117 url: string,
118 params: Parameters<typeof fetch>[1],
119 timeoutMs = DEFAULT_FETCH_TIMEOUT_MS,
120): Promise<Response> => {
121 let timeoutId: ReturnType<typeof setTimeout> | undefined;
122
123 return Promise.race([
124 enhancedFetch(url, params),
125 new Promise<Response>((_, reject) => {
126 timeoutId = setTimeout(() => {
127 log('fetch timeout', url);
128 reject(Error(i18n.t('error_ping_timeout')));
129 }, timeoutMs);
130 }),
131 ]).finally(() => {
132 if (timeoutId) {
133 clearTimeout(timeoutId);
134 }
135 });
136};
137
138export const enhancedFetch = async (
139 url: string,

Callers 2

PushyClass · 0.90
utils.tsFile · 0.85

Calls 3

enhancedFetchFunction · 0.85
logFunction · 0.85
tMethod · 0.80

Tested by

no test coverage detected