import { CancelToken , RequestConfiguration } from './cancelRequests' ; export const ensureTimeout = async ( innerFunction , reqConfig ? ) : Promise < any > => { if ( ! reqConfig || ! reqConfig . timeout ) { return await innerFunction ( reqConfig ) ; } const innerReqConfig = { ... reqConfig , cancelToken : reqConfig . cancelToken ? reqConfig . cancelToken : new CancelToken ( ) , timeout : undefined , } ; const timer = setTimeout ( ( ) => { innerReqConfig . cancelToken . cancel ( ) ; } , reqConfig . timeout ) ; try { const resolvedValue = await innerFunction ( innerReqConfig ) ; clearTimeout ( timer ) ; return resolvedValue ; } catch ( e ) { clearTimeout ( timer ) ; throw e ; } } ;