MCPcopy Create free account
hub / github.com/deanrad/rxfx / monitorHandler

Function monitorHandler

service/src/modifyHandler.ts:58–83  ·  view source on GitHub ↗
(
  opts: MonitorOptions,
  handler: (req: TRequest) => ObservableInput<TNext>
)

Source from the content-addressed store, hash-verified

56 * Useful for getting progress events from effects that don't notify of progress intrinsically.
57 */
58export 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}

Callers 1

Calls 1

handlerFunction · 0.50

Tested by

no test coverage detected