From 2a665708deb91ecad4120f79167caf177a42074b Mon Sep 17 00:00:00 2001 From: "Andrew W. Harn" Date: Tue, 19 Nov 2024 16:22:08 -0500 Subject: [PATCH] Update abortSearch logic and documentation Signed-off-by: Andrew W. Harn --- packages/zosfiles/src/methods/search/Search.ts | 15 +++++++++++++-- .../src/methods/search/doc/ISearchOptions.ts | 4 +++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/zosfiles/src/methods/search/Search.ts b/packages/zosfiles/src/methods/search/Search.ts index 7c39387c3..25cffe784 100644 --- a/packages/zosfiles/src/methods/search/Search.ts +++ b/packages/zosfiles/src/methods/search/Search.ts @@ -246,9 +246,14 @@ export class Search { const failures: string[] = []; const total = searchItems.length; let complete = 0; + let searchAborted = false; const createSearchPromise = async (searchItem: ISearchItem) => { - if (!this.timerExpired && !(searchOptions.abortSearch && searchOptions.abortSearch())) { + if (!this.timerExpired && !searchAborted) { + if (searchOptions.abortSearch && searchOptions.abortSearch()) { + searchAborted = true; + } + // Update the progress bar if (searchOptions.progressTask) { // eslint-disable-next-line @typescript-eslint/no-magic-numbers @@ -309,8 +314,14 @@ export class Search { const failures: string[] = []; const total = searchItems.length; let complete = 0; + let searchAborted = false; + const createFindPromise = async (searchItem: ISearchItem) => { - if (!this.timerExpired && !(searchOptions.abortSearch && searchOptions.abortSearch())) { + if (!this.timerExpired && !searchAborted) { + if (searchOptions.abortSearch && searchOptions.abortSearch()) { + searchAborted = true; + } + // Handle the progress bars if (searchOptions.progressTask) { if (searchOptions.mainframeSearch) { diff --git a/packages/zosfiles/src/methods/search/doc/ISearchOptions.ts b/packages/zosfiles/src/methods/search/doc/ISearchOptions.ts index 6d53680f9..b554b976f 100644 --- a/packages/zosfiles/src/methods/search/doc/ISearchOptions.ts +++ b/packages/zosfiles/src/methods/search/doc/ISearchOptions.ts @@ -46,6 +46,8 @@ export interface ISearchOptions { /* If true, continue search. If false, terminate search. */ continueSearch?: (dataSets: IDataSet[]) => Promise | boolean; - /* A function that gets called to validate whether or not to abort if a timeout isn't specified */ + /* A function that gets called to validate whether or not to abort if a timeout isn't specified. */ + /* If abortSearch returns true, then the search should terminate immediately with the current available results. */ + /* This prevents searches from continuing to run in the background in the case that a user wishes to cancel a search (i.e. in VS Code) */ abortSearch?: () => boolean; } \ No newline at end of file