mirror of
https://iceshrimp.dev/iceshrimp/iceshrimp
synced 2024-12-05 10:18:05 +09:00
Refactor
This commit is contained in:
parent
c3e83c9903
commit
a3c5a2d767
@ -7,16 +7,17 @@ type AwaitAll<T> = {
|
||||
export async function awaitAll<T>(obj: T): Promise<AwaitAll<T>> {
|
||||
const target = {} as any;
|
||||
const keys = Object.keys(obj);
|
||||
const rawValues = Object.values(obj);
|
||||
const retValues = ((values: any[]): any[] =>
|
||||
values.map(value => {
|
||||
if (!value || !value.constructor || value.constructor.name !== 'Object') return value;
|
||||
return awaitAll(value);
|
||||
})
|
||||
)(rawValues);
|
||||
const values = await Promise.all(retValues);
|
||||
for (let i = 0; i < values.length; i++) {
|
||||
target[keys[i]] = values[i];
|
||||
const values = Object.values(obj);
|
||||
|
||||
const resolvedValues = await Promise.all(values.map(value =>
|
||||
(value || !value.constructor || value.constructor.name !== 'Object')
|
||||
? value
|
||||
: awaitAll(value)
|
||||
));
|
||||
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
target[keys[i]] = resolvedValues[i];
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user