From 61c99ffb941c401e3c5471e96db9f2bbdec78d7a Mon Sep 17 00:00:00 2001 From: pgayvallet Date: Fri, 27 Oct 2023 16:39:26 +0200 Subject: [PATCH] using throttle with leading and trailing --- x-pack/plugins/licensing/common/license_update.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/licensing/common/license_update.ts b/x-pack/plugins/licensing/common/license_update.ts index b344d8ce2d16a..a35b7aa6e6785 100644 --- a/x-pack/plugins/licensing/common/license_update.ts +++ b/x-pack/plugins/licensing/common/license_update.ts @@ -17,6 +17,7 @@ import { takeUntil, finalize, startWith, + throttleTime, } from 'rxjs/operators'; import { hasLicenseInfoChanged } from './has_license_info_changed'; import type { ILicense } from './types'; @@ -29,11 +30,15 @@ export function createLicenseUpdate( ) { const manuallyRefresh$ = new Subject(); - const fetched$ = merge(triggerRefresh$, manuallyRefresh$).pipe( - takeUntil(stop$), - exhaustMap(fetcher), - share() - ); + const fetched$ = merge( + triggerRefresh$, + manuallyRefresh$.pipe( + throttleTime(1000, undefined, { + leading: true, + trailing: true, + }) + ) + ).pipe(takeUntil(stop$), exhaustMap(fetcher), share()); // provide a first, empty license, so that we can compare in the filter below const startWithArgs = initialValues ? [undefined, initialValues] : [undefined];