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

Function timeoutHandler

service/src/modifyHandler.ts:27–51  ·  view source on GitHub ↗
(
  opts: TimeoutOptions<TRequest, TError>,
  handler: (req: TRequest) => ObservableInput<TNext> // type of arg2 of .listen
)

Source from the content-addressed store, hash-verified

25 * times out with the specified duration and errorFactory.
26 */
27export function timeoutHandler<TRequest, TNext, TError = Error>(
28 opts: TimeoutOptions<TRequest, TError>,
29 handler: (req: TRequest) => ObservableInput<TNext> // type of arg2 of .listen
30): (req: TRequest) => ObservableInput<TNext> {
31 const timeout = opts.duration;
32 if (!timeout) return handler;
33
34 const duration = timeout;
35
36 const errFactory = opts.errorFactory
37 ? opts.errorFactory
38 : (_req: TRequest) => {
39 return new Error(`Rxfx process timed out in ${duration} ms`);
40 };
41
42 return (req: TRequest) => {
43 const handlingResult = handler(req);
44 const timerOut = after(
45 duration,
46 throwError(() => errFactory(req))
47 ) as typeof handlingResult;
48
49 return race(handlingResult, timerOut);
50 };
51}
52
53/** Decorates a handler such that when it is running, the given `progressCallback` is invoked
54 * at the specified interval, passing the interval time in msec as an option.

Callers 1

Calls 2

afterFunction · 0.90
handlerFunction · 0.50

Tested by

no test coverage detected