Skip to content

Commit

Permalink
don’t delay search requests if 0 ms delay
Browse files Browse the repository at this point in the history
fix test

fix
  • Loading branch information
Dosant committed May 1, 2020
1 parent 2f6ce26 commit 203f62c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/plugins/data/public/search/fetch/fetch_soon.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('fetchSoon', () => {
(callClient as jest.Mock).mockClear();
});

test('should delay by 0ms if config is set to not batch searches', () => {
test('should execute asap if config is set to not batch searches', () => {
const config = getConfigStub({
'courier:batchSearches': false,
});
Expand All @@ -67,8 +67,6 @@ describe('fetchSoon', () => {

fetchSoon(request, options, { config } as FetchHandlers);

expect(callClient).not.toBeCalled();
jest.advanceTimersByTime(0);
expect(callClient).toBeCalled();
});

Expand Down
4 changes: 4 additions & 0 deletions src/plugins/data/public/search/fetch/fetch_soon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ async function delayedFetch(
fetchHandlers: FetchHandlers,
ms: number
) {
if (ms === 0) {
return callClient([request], [options], fetchHandlers)[0];
}

const i = requestsToFetch.length;
requestsToFetch = [...requestsToFetch, request];
requestOptions = [...requestOptions, options];
Expand Down

0 comments on commit 203f62c

Please sign in to comment.