Skip to content

Commit

Permalink
using throttle with leading and trailing
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Oct 27, 2023
1 parent e3ada35 commit 61c99ff
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions x-pack/plugins/licensing/common/license_update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
takeUntil,
finalize,
startWith,
throttleTime,
} from 'rxjs/operators';
import { hasLicenseInfoChanged } from './has_license_info_changed';
import type { ILicense } from './types';
Expand All @@ -29,11 +30,15 @@ export function createLicenseUpdate(
) {
const manuallyRefresh$ = new Subject<void>();

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];
Expand Down

0 comments on commit 61c99ff

Please sign in to comment.