mirror of
https://github.com/whscullin/apple2js.git
synced 2024-01-12 14:14:38 +00:00
Promises, promises
This commit is contained in:
parent
40bc862389
commit
a55baa3f25
|
@ -13,7 +13,7 @@ import { Screen } from './Screen';
|
|||
import { Drives } from './Drives';
|
||||
import { Slinky } from './Slinky';
|
||||
import { ThunderClock } from './ThunderClock';
|
||||
import { Ready } from './util/promises';
|
||||
import { noAwait, Ready } from './util/promises';
|
||||
|
||||
import styles from './css/Apple2.module.css';
|
||||
|
||||
|
@ -55,17 +55,19 @@ export const Apple2 = (props: Apple2Props) => {
|
|||
...props,
|
||||
};
|
||||
const apple2 = new Apple2Impl(options);
|
||||
apple2.ready.then(() => {
|
||||
setApple2(apple2);
|
||||
const io = apple2.getIO();
|
||||
const cpu = apple2.getCPU();
|
||||
setIO(io);
|
||||
setCPU(cpu);
|
||||
return drivesReady.promise.then(() => {
|
||||
noAwait((async () => {
|
||||
try {
|
||||
await apple2.ready;
|
||||
setApple2(apple2);
|
||||
setIO(apple2.getIO());
|
||||
setCPU(apple2.getCPU());
|
||||
await drivesReady.ready;
|
||||
apple2.reset();
|
||||
apple2.run();
|
||||
});
|
||||
}).catch((e) => setError(e));
|
||||
} catch (e) {
|
||||
setError(e);
|
||||
}
|
||||
}))();
|
||||
}
|
||||
}, [props, drivesReady]);
|
||||
|
||||
|
|
|
@ -17,12 +17,15 @@ export function noAwait<F extends (...args: unknown[]) => Promise<unknown>>(f: F
|
|||
*/
|
||||
|
||||
export class Ready {
|
||||
onError: (value?: unknown) => void;
|
||||
onReady: (value?: unknown) => void;
|
||||
promise: Promise<unknown>;
|
||||
|
||||
ready: Promise<unknown>;
|
||||
|
||||
constructor() {
|
||||
this.promise = new Promise((resolve, _reject) => {
|
||||
this.ready = new Promise((resolve, reject) => {
|
||||
this.onReady = resolve;
|
||||
this.onError = reject;
|
||||
}).catch(console.error);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user