Conversation
b94d44d to
0307be4
Compare
0307be4 to
c5ea00a
Compare
c5ea00a to
0c10c57
Compare
| } | ||
|
|
||
| func (el *EventListener) Listen(fromBlock *big.Int, eventCh chan<- *ContractEvent, stop <-chan struct{}) error { | ||
| func (el *EventListener) Listen(fromBlock *big.Int, stop <-chan struct{}) error { |
There was a problem hiding this comment.
return eventCh <-chan *ContractEvent?
There was a problem hiding this comment.
But Listen() will be blocked until listening service terminated.
There was a problem hiding this comment.
Since we have the whole instance of EventListener returned after New(), and since both logCh and eventCh are included in EventListener struct, caller can access eventCh directly.
There was a problem hiding this comment.
So how could caller access eventCh? It's a private variable.
| el.eventCh <- cEvent | ||
| } | ||
| } | ||
| close(el.eventCh) |
There was a problem hiding this comment.
So we don't wait until the events are processed?
There was a problem hiding this comment.
Receiver can still get data from channel even after sender closing it. The reason that sender HAS to close channel is to let receiver know there is nomore data.
There was a problem hiding this comment.
Receiver can still get data from channel even after sender closing it.
I don't think so. @tailingchen how about your thoughts?
| } | ||
|
|
||
| func (el *EventListener) Listen(fromBlock *big.Int, eventCh chan<- *ContractEvent, stop <-chan struct{}) error { | ||
| func (el *EventListener) Listen(fromBlock *big.Int, stop <-chan struct{}) error { |
There was a problem hiding this comment.
So how could caller access eventCh? It's a private variable.
Goal
eventChThe responsibility of creating and managing a channel should belongs to the sender (which is event listener in this case). So instead of getting channel from Listen() parameter, event listener keep 2 channel inside of it's struct. |
No description provided.