( opts: MonitorOptions, handler: (req: TRequest) => ObservableInput<TNext> )
| 56 | * Useful for getting progress events from effects that don't notify of progress intrinsically. |
| 57 | */ |
| 58 | export function monitorHandler<TRequest, TNext>( |
| 59 | opts: MonitorOptions, |
| 60 | handler: (req: TRequest) => ObservableInput<TNext> |
| 61 | ): (req: TRequest) => Observable<TNext> { |
| 62 | const { interval, progressCallback } = opts; |
| 63 | return (req: TRequest) => { |
| 64 | const monitorElapsed = rxjsInterval(interval).pipe( |
| 65 | map((i) => (i + 1) * interval), |
| 66 | startWith(0) |
| 67 | ); |
| 68 | |
| 69 | let monitorSub = new Subscription(); |
| 70 | const handlingResult = from(handler(req)).pipe( |
| 71 | tap({ |
| 72 | subscribe() { |
| 73 | monitorSub = monitorElapsed.subscribe({ next: progressCallback }); |
| 74 | }, |
| 75 | finalize() { |
| 76 | monitorSub.unsubscribe(); |
| 77 | }, |
| 78 | }) |
| 79 | ); |
| 80 | |
| 81 | return handlingResult; |
| 82 | }; |
| 83 | } |
no test coverage detected