File tree 1 file changed +5
-4
lines changed
1 file changed +5
-4
lines changed Original file line number Diff line number Diff line change 1
1
import { Observable , type Subscription } from 'rxjs'
2
2
3
- import type { Bus , ControlLines } from '../bus/bus'
3
+ import type { Bus } from '../bus/bus'
4
4
import type { Clock } from '../clock/clock'
5
5
import type { Cpu } from '../cpu/cpu'
6
6
import type { Memory } from '../memory/memory'
@@ -16,22 +16,23 @@ export class Controller {
16
16
step = ( ) : Observable < void > => {
17
17
return new Observable < void > ( ( subscriber ) => {
18
18
const step = this . cpu . step ( )
19
- let subscription : Subscription
19
+ let subscription : Subscription | undefined
20
20
21
- const handleResult = ( result : IteratorResult < Observable < ControlLines > , void > ) => {
21
+ const handleResult = ( result : ReturnType < typeof step . next > ) => {
22
22
if ( result . done ) {
23
23
subscriber . next ( )
24
24
subscriber . complete ( )
25
25
return
26
26
}
27
27
queueMicrotask ( this . clock . tick )
28
+ subscription ?. unsubscribe ( )
28
29
subscription = result . value . subscribe ( ( signals ) => {
29
30
handleResult ( step . next ( signals ) )
30
31
} )
31
32
}
32
33
33
34
handleResult ( step . next ( ) )
34
- return ( ) => subscription . unsubscribe ( )
35
+ return ( ) => subscription ? .unsubscribe ( )
35
36
} )
36
37
}
37
38
}
You can’t perform that action at this time.
0 commit comments