Skip to content

Commit fef49f9

Browse files
committed
fix(core): handle step result
1 parent 26554ea commit fef49f9

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/core/controller/controller.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Observable, type Subscription } from 'rxjs'
22

3-
import type { Bus, ControlLines } from '../bus/bus'
3+
import type { Bus } from '../bus/bus'
44
import type { Clock } from '../clock/clock'
55
import type { Cpu } from '../cpu/cpu'
66
import type { Memory } from '../memory/memory'
@@ -16,22 +16,23 @@ export class Controller {
1616
step = (): Observable<void> => {
1717
return new Observable<void>((subscriber) => {
1818
const step = this.cpu.step()
19-
let subscription: Subscription
19+
let subscription: Subscription | undefined
2020

21-
const handleResult = (result: IteratorResult<Observable<ControlLines>, void>) => {
21+
const handleResult = (result: ReturnType<typeof step.next>) => {
2222
if (result.done) {
2323
subscriber.next()
2424
subscriber.complete()
2525
return
2626
}
2727
queueMicrotask(this.clock.tick)
28+
subscription?.unsubscribe()
2829
subscription = result.value.subscribe((signals) => {
2930
handleResult(step.next(signals))
3031
})
3132
}
3233

3334
handleResult(step.next())
34-
return () => subscription.unsubscribe()
35+
return () => subscription?.unsubscribe()
3536
})
3637
}
3738
}

0 commit comments

Comments
 (0)