Optimize unnecessary uses of new Promise() (#4442)

* Optimize out unnecessary uses of new Promise()

* tweak

---------

Co-authored-by: pngwn <hello@pngwn.io>
This commit is contained in:
Aarni Koskela 2023-06-08 05:49:09 +03:00 committed by GitHub
parent ff6e676a92
commit 9c5a1d871c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 28 deletions

View File

@ -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.

View File

@ -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<

View File

@ -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() {