Skip to content

Commit 4833ae1

Browse files
committed
fix: remove promise race conditions for batch utilities
1 parent 4c77bff commit 4833ae1

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

site/src/pages/WorkspacesPage/batchActions.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,14 @@ export function useBatchActions(
7878
},
7979
});
8080

81-
// We have to explicitly make the mutation functions for the
82-
// favorite/unfavorite functionality be async and then void out the
83-
// Promise.all result because otherwise the return type becomes a void
84-
// array, which doesn't ever make sense with TypeScript's type system
81+
// Not a great idea to return the promises from the Promise.all calls below
82+
// because that then gives you a void array, which doesn't make sense with
83+
// TypeScript's type system. Best to await them, and then have the wrapper
84+
// mutation function return its own void promise
85+
8586
const favoriteAllMutation = useMutation({
8687
mutationFn: async (workspaces: readonly Workspace[]) => {
87-
void Promise.all(
88+
await Promise.all(
8889
workspaces
8990
.filter((w) => !w.favorite)
9091
.map((w) => API.putFavoriteWorkspace(w.id)),
@@ -98,7 +99,7 @@ export function useBatchActions(
9899

99100
const unfavoriteAllMutation = useMutation({
100101
mutationFn: async (workspaces: readonly Workspace[]) => {
101-
void Promise.all(
102+
await Promise.all(
102103
workspaces
103104
.filter((w) => w.favorite)
104105
.map((w) => API.deleteFavoriteWorkspace(w.id)),

0 commit comments

Comments
 (0)