@bemedev/rx-add-ons
Version:
A collection of RxJS operators and utilities to enhance reactive programming capabilities.
60 lines • 2.23 kB
TypeScript
import { Observable } from 'rxjs';
/**
* Switches to a fallback Observable if the source doesn't emit within the specified timeout.
* Unlike the standard timeout operator, this doesn't error but switches to the fallback.
*
* @param timeout - Timeout duration in milliseconds
* @param fallback - Observable to switch to on timeout
* @returns A function that returns an Observable that emits from source or fallback
*
* @example
* ```typescript
* // Switch to fallback after 5 seconds
* source$.pipe(
* timeoutWithFallback(5000, of('timeout'))
* )
*
* // Switch to alternative data source on timeout
* source$.pipe(
* timeoutWithFallback(3000, alternativeSource$)
* )
* ```
*/
export declare const timeoutWithFallback: <T>(timeout: number, fallback?: Observable<T>) => ((source: Observable<T>) => Observable<T>);
/**
* Switches to a fallback Observable if the source doesn't emit within the specified timeout.
* Unlike the standard timeout operator, this doesn't error but switches to the fallback.
*
* @param timeout - Timeout duration in milliseconds
* @param fallback - Observable to switch to on timeout
* @returns A function that returns an Observable that emits from source or fallback
*
* @example
* ```typescript
* // Switch to fallback after 5 seconds
* source$.pipe(
* timeoutWithFallback(5000, of('timeout'))
* )
*
* // Switch to alternative data source on timeout
* source$.pipe(
* timeoutWithFallback(3000, alternativeSource$)
* )
* ```
*/
export declare const timeout: <T>(timeout: number, fallback?: Observable<T>) => ((source: Observable<T>) => Observable<T>);
/**
* Timeout with fallback that can be configured per emission
* Resets timeout on each emission from source
*
* @see {@linkcode timeoutWithFallback}
*/
export declare const tickWithFallback: <T>(timeout: number, fallback?: Observable<T>) => ((source: Observable<T>) => Observable<T>);
/**
* Timeout with fallback that can be configured per emission
* Resets timeout on each emission from source
*
* @see {@linkcode timeoutWithFallback}
*/
export declare const tick: <T>(timeout: number, fallback?: Observable<T>) => ((source: Observable<T>) => Observable<T>);
//# sourceMappingURL=time.d.ts.map