Skip to content

Commit

Permalink
EMT-451: use loop, remove await
Browse files Browse the repository at this point in the history
  • Loading branch information
nnamdifrankie committed Jun 25, 2020
1 parent b310f92 commit 46d2130
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,18 @@ export async function findAllUnenrolledHostIds(client: IScopedClusterClient): Pr
HostId
>;

// eslint-disable-next-line no-return-await
return await fetchAllUnenrolledHostIdsWithScroll(response, client.callAsCurrentUser);
return fetchAllUnenrolledHostIdsWithScroll(response, client.callAsCurrentUser);
}

export async function fetchAllUnenrolledHostIdsWithScroll(
response: SearchResponse<HostId>,
client: APICaller,
hits: HostId[] = []
): Promise<HostId[]> {
const newHits = response.hits?.hits || [];
const scrollId = response._scroll_id;
let newHits = response.hits?.hits || [];
let scrollId = response._scroll_id;

if (newHits.length > 0) {
while (newHits.length > 0) {
const hostIds: HostId[] = newHits.map((hitSource: HitSource) => hitSource._source);
hits.push(...hostIds);

Expand All @@ -108,8 +107,8 @@ export async function fetchAllUnenrolledHostIdsWithScroll(
},
});

// eslint-disable-next-line no-return-await
return await fetchAllUnenrolledHostIdsWithScroll(innerResponse, client, hits);
newHits = innerResponse.hits?.hits || [];
scrollId = innerResponse._scroll_id;
}
return hits;
}

0 comments on commit 46d2130

Please sign in to comment.