Skip to content

Commit

Permalink
remove background busyspin for the case where concurrency = 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Soopyboo32 committed Sep 26, 2024
1 parent a6e2f68 commit 367e4ce
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions src/screens/GlobalSearchScreen/hooks/useGlobalSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,33 @@ export const useGlobalSearch = ({ defaultSearchText }: Props) => {
);

(async () => {
for (let _plugin of filteredSortedInstalledPlugins) {
while (running >= globalSearchConcurrency || !isFocused.current) {
await new Promise(resolve => setTimeout(resolve, 100));
if (globalSearchConcurrency > 1) {
for (let _plugin of filteredSortedInstalledPlugins) {
while (running >= globalSearchConcurrency || !isFocused.current) {
await new Promise(resolve => setTimeout(resolve, 100));
}
if (!isMounted.current) {
break;
}
running++;
searchInPlugin(_plugin)
.then(() => {
running--;
})
.catch(() => {
running--;
});
}
if (!isMounted.current) {
break;
} else {
for (let _plugin of filteredSortedInstalledPlugins) {
if (!isMounted.current) {
break;
}
while (!isFocused.current) {
await new Promise(resolve => setTimeout(resolve, 100));
}
await searchInPlugin(_plugin);
}
running++;
searchInPlugin(_plugin)
.then(() => {
running--;
})
.catch(() => {
running--;
});
}
})();
};
Expand Down

0 comments on commit 367e4ce

Please sign in to comment.