diff --git a/js/components/Apple2.tsx b/js/components/Apple2.tsx index 62db867..feb9a48 100644 --- a/js/components/Apple2.tsx +++ b/js/components/Apple2.tsx @@ -13,7 +13,7 @@ import { Screen } from './Screen'; import { Drives } from './Drives'; import { Slinky } from './Slinky'; import { ThunderClock } from './ThunderClock'; -import { noAwait, Ready } from './util/promises'; +import { spawn, Ready } from './util/promises'; import styles from './css/Apple2.module.css'; @@ -55,7 +55,7 @@ export const Apple2 = (props: Apple2Props) => { ...props, }; const apple2 = new Apple2Impl(options); - noAwait((async () => { + spawn(async () => { try { await apple2.ready; setApple2(apple2); @@ -67,7 +67,7 @@ export const Apple2 = (props: Apple2Props) => { } catch (e) { setError(e); } - }))(); + }); } }, [props, drivesReady]); diff --git a/js/components/util/promises.ts b/js/components/util/promises.ts index ee8e872..d04aa72 100644 --- a/js/components/util/promises.ts +++ b/js/components/util/promises.ts @@ -11,6 +11,14 @@ export function noAwait Promise>(f: F return f as NoAwait; } +/** + * Calls the given `Promise`-returning function and returns void, signalling that it is + * explicitly not awaited. + */ +export function spawn(f: () => Promise): void { + noAwait(f)(); +} + /** * Utility class that allows a promise to be passed to a * service to be resolved.