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
runAfterRuntimeInitialized(callback: () => Promise<void>){
runAfterRuntimeInitialized(callback: () => Promise<void>) {
runtimeLoaded.subscribe(value => {
if ('run' in value) {
setTimeout(async () => {
await callback();
setTimeout(() => {
void callback();
}, 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
// so we need to replace using the promise and actually using
// the interpreter after it loads completely
// setTimeout(async () => {
// setTimeout(() => {
// void (async () => {
// await this.eval(this.code);
// this.proxy = this.proxyClass(this);
// console.log('proxy', this.proxy);
// this.proxy.connect();
// this.registerWidget();
// })();
// }, 2000);
runtimeLoaded.subscribe(value => {
console.log('RUNTIME READY', value);
if ('run' in value) {
runtime = value;
setTimeout(async () => {
setTimeout(() => {
void (async () => {
await this.eval(this.code);
this.proxy = this.proxyClass(this);
console.log('proxy', this.proxy);
this.proxy.connect();
this.registerWidget();
})();
}, 1000);
}
});