Fix misused promises (#723)

* Remove an unnecessary await

* Add an async IIFE wrapper
This commit is contained in:
woxtu
2022-08-26 05:47:29 +09:00
committed by GitHub
parent ccb0e6b269
commit b0e56577b5

View File

@@ -194,11 +194,11 @@ export class BaseEvalElement extends HTMLElement {
} }
} // end eval } // end eval
runAfterRuntimeInitialized(callback: () => Promise<void>){ runAfterRuntimeInitialized(callback: () => Promise<void>) {
runtimeLoaded.subscribe(value => { runtimeLoaded.subscribe(value => {
if ('run' in value) { if ('run' in value) {
setTimeout(async () => { setTimeout(() => {
await callback(); void callback();
}, 100); }, 100);
} }
}); });
@@ -231,23 +231,27 @@ function createWidget(name: string, code: string, klass: string) {
// ideally we can just wait for it to load and then run. To do // ideally we can just wait for it to load and then run. To do
// so we need to replace using the promise and actually using // so we need to replace using the promise and actually using
// the interpreter after it loads completely // the interpreter after it loads completely
// setTimeout(async () => { // setTimeout(() => {
// void (async () => {
// await this.eval(this.code); // await this.eval(this.code);
// this.proxy = this.proxyClass(this); // this.proxy = this.proxyClass(this);
// console.log('proxy', this.proxy); // console.log('proxy', this.proxy);
// this.proxy.connect(); // this.proxy.connect();
// this.registerWidget(); // this.registerWidget();
// })();
// }, 2000); // }, 2000);
runtimeLoaded.subscribe(value => { runtimeLoaded.subscribe(value => {
console.log('RUNTIME READY', value); console.log('RUNTIME READY', value);
if ('run' in value) { if ('run' in value) {
runtime = value; runtime = value;
setTimeout(async () => { setTimeout(() => {
void (async () => {
await this.eval(this.code); await this.eval(this.code);
this.proxy = this.proxyClass(this); this.proxy = this.proxyClass(this);
console.log('proxy', this.proxy); console.log('proxy', this.proxy);
this.proxy.connect(); this.proxy.connect();
this.registerWidget(); this.registerWidget();
})();
}, 1000); }, 1000);
} }
}); });