UNPKG

@kirz/react-native-toolkit

Version:

Toolkit to speed up React Native development

15 lines (14 loc) 348 B
export function timeout<T>( promise: T, timeout: number | null = 5000, error?: string, ) { return Promise.race<T>([ typeof promise === 'function' ? promise() : promise, new Promise((_, reject) => { if (timeout !== null) { setTimeout(() => reject(new Error(error ?? 'Timeout error')), timeout); } }), ]); }