Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize unnecessary uses of new Promise() #4442

Merged
merged 3 commits into from Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions CHANGELOG.md
Expand Up @@ -10,8 +10,7 @@ No changes to highlight.

## Other Changes:

No changes to highlight.

- Clean up unnecessary `new Promise()`s by [@akx](https://github.com/akx) in [PR 4442](https://github.com/gradio-app/gradio/pull/4442).
## Breaking Changes:

No changes to highlight.
Expand Down
26 changes: 12 additions & 14 deletions js/app/src/Blocks.svelte
Expand Up @@ -135,25 +135,23 @@
document?: (arg0: Record<string, unknown>) => Documentation;
};

function load_component<T extends ComponentMeta["type"]>(
async function load_component<T extends ComponentMeta["type"]>(
name: T
): Promise<{
name: T;
component: LoadedComponent;
}> {
return new Promise(async (res, rej) => {
try {
const c = await component_map[name]();
res({
name,
component: c as LoadedComponent
});
} catch (e) {
console.error("failed to load: " + name);
console.error(e);
rej(e);
}
});
try {
const c = await component_map[name]();
return {
name,
component: c as LoadedComponent
};
} catch (e) {
console.error(`failed to load: ${name}`);
console.error(e);
throw e;
}
}

const component_set = new Set<
Expand Down
17 changes: 5 additions & 12 deletions js/app/src/components/StatusTracker/Loader.svelte
Expand Up @@ -9,18 +9,11 @@

let dismounted: boolean;

function animate(): Promise<void> {
return new Promise(async (res) => {
await Promise.all([top.set([125, 140]), bottom.set([-125, -140])]);

await Promise.all([top.set([-125, 140]), bottom.set([125, -140])]);

await Promise.all([top.set([-125, 0]), bottom.set([125, -0])]);

await Promise.all([top.set([125, 0]), bottom.set([-125, 0])]);

res();
});
async function animate() {
await Promise.all([top.set([125, 140]), bottom.set([-125, -140])]);
await Promise.all([top.set([-125, 140]), bottom.set([125, -140])]);
await Promise.all([top.set([-125, 0]), bottom.set([125, -0])]);
await Promise.all([top.set([125, 0]), bottom.set([-125, 0])]);
}

async function run() {
Expand Down