Skip to content

Commit

Permalink
use a single fromEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Feb 23, 2022
1 parent 302f5aa commit 19b120b
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/core/server/http/router/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { URL } from 'url';
import uuid from 'uuid';
import { Request, RouteOptionsApp, RequestApplicationState, RouteOptions } from '@hapi/hapi';
import { Observable, fromEvent, merge } from 'rxjs';
import { shareReplay, first, takeUntil, filter } from 'rxjs/operators';
import { shareReplay, first, takeUntil, filter, share } from 'rxjs/operators';
import { RecursiveReadonly } from '@kbn/utility-types';
import { deepFreeze } from '@kbn/std';

Expand Down Expand Up @@ -216,19 +216,17 @@ export class KibanaRequest<
}

private getEvents(request: Request): KibanaRequestEvents {
const closed$ = fromEvent<void>(request.raw.res, 'close').pipe(share());

// the response is completed
const finished$ = fromEvent<void>(request.raw.res, 'close').pipe(
filter(() => {
return isCompleted(request);
}),
const finished$ = closed$.pipe(
filter(() => isCompleted(request)),
first()
);

// the response's underlying connection was terminated prematurely
const aborted$ = fromEvent<void>(request.raw.res, 'close').pipe(
filter(() => {
return !isCompleted(request);
}),
const aborted$ = closed$.pipe(
filter(() => !isCompleted(request)),
first(),
takeUntil(finished$)
);
Expand Down

0 comments on commit 19b120b

Please sign in to comment.