-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
113 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export type PromisesMap<T> = { | ||
[K in keyof T]: Promise<T[K]>; | ||
}; | ||
|
||
export async function resolveObjectPromises<T>( | ||
obj: PromisesMap<T>, | ||
): Promise<T> { | ||
// Convert the object into an array of [key, promise] pairs | ||
const entries = Object.entries(obj) as [keyof T, Promise<any>][]; | ||
|
||
// Use Promise.all to wait for all the promises to resolve | ||
const resolvedEntries = await Promise.all( | ||
entries.map(async ([key, promise]) => { | ||
const value = await promise; | ||
return [key, value] as [keyof T, T[keyof T]]; | ||
}), | ||
); | ||
|
||
// Convert the array of resolved [key, value] pairs back into an object | ||
return Object.fromEntries(resolvedEntries) as T; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.