Skip to content

Commit

Permalink
Update abortSearch logic and documentation
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew W. Harn <[email protected]>
  • Loading branch information
awharn committed Nov 19, 2024
1 parent 85fe390 commit 2a66570
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 13 additions & 2 deletions packages/zosfiles/src/methods/search/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion packages/zosfiles/src/methods/search/doc/ISearchOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export interface ISearchOptions {
/* If true, continue search. If false, terminate search. */
continueSearch?: (dataSets: IDataSet[]) => Promise<boolean> | 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;
}

0 comments on commit 2a66570

Please sign in to comment.