@@ -33,7 +33,10 @@ type handler struct {
33
33
transactionsListenerHandler * listenerHanlder [* arkv1.GetTransactionsStreamResponse ]
34
34
addressSubsHandler * listenerHanlder [* arkv1.SubscribeForAddressResponse ]
35
35
36
- stopCh <- chan struct {}
36
+ stopCh <- chan struct {}
37
+ stopRoundEventsCh chan struct {}
38
+ stopTransactionEventsCh chan struct {}
39
+ stopAddressEventsCh chan struct {}
37
40
}
38
41
39
42
func NewHandler (version string , service application.Service , stopCh <- chan struct {}) service {
@@ -44,8 +47,12 @@ func NewHandler(version string, service application.Service, stopCh <-chan struc
44
47
transactionsListenerHandler : newListenerHandler [* arkv1.GetTransactionsStreamResponse ](),
45
48
addressSubsHandler : newListenerHandler [* arkv1.SubscribeForAddressResponse ](),
46
49
stopCh : stopCh ,
50
+ stopRoundEventsCh : make (chan struct {}, 1 ),
51
+ stopTransactionEventsCh : make (chan struct {}, 1 ),
52
+ stopAddressEventsCh : make (chan struct {}, 1 ),
47
53
}
48
54
55
+ go h .listenToStop ()
49
56
go h .listenToEvents ()
50
57
go h .listenToTxEvents ()
51
58
@@ -304,7 +311,7 @@ func (h *handler) GetEventStream(
304
311
305
312
for {
306
313
select {
307
- case <- h .stopCh :
314
+ case <- h .stopRoundEventsCh :
308
315
return nil
309
316
case <- stream .Context ().Done ():
310
317
return nil
@@ -456,6 +463,8 @@ func (h *handler) GetTransactionsStream(
456
463
457
464
for {
458
465
select {
466
+ case <- h .stopTransactionEventsCh :
467
+ return nil
459
468
case <- stream .Context ().Done ():
460
469
return nil
461
470
case ev := <- listener .ch :
@@ -524,6 +533,8 @@ func (h *handler) SubscribeForAddress(
524
533
525
534
for {
526
535
select {
536
+ case <- h .stopAddressEventsCh :
537
+ return nil
527
538
case <- stream .Context ().Done ():
528
539
return nil
529
540
case ev := <- listener .ch :
@@ -534,6 +545,14 @@ func (h *handler) SubscribeForAddress(
534
545
}
535
546
}
536
547
548
+ func (h * handler ) listenToStop () {
549
+ <- h .stopCh
550
+ h .stopRoundEventsCh <- struct {}{}
551
+ h .stopTransactionEventsCh <- struct {}{}
552
+ h .stopAddressEventsCh <- struct {}{}
553
+
554
+ }
555
+
537
556
// listenToEvents forwards events from the application layer to the set of listeners
538
557
func (h * handler ) listenToEvents () {
539
558
channel := h .svc .GetEventsChannel (context .Background ())
0 commit comments