Skip to content

Refine event listener#5

Open
charlesjhongc wants to merge 2 commits intomasterfrom
Refine-event-listener
Open

Refine event listener#5
charlesjhongc wants to merge 2 commits intomasterfrom
Refine-event-listener

Conversation

@charlesjhongc
Copy link

No description provided.

@charlesjhongc charlesjhongc force-pushed the Refine-event-listener branch 3 times, most recently from b94d44d to 0307be4 Compare May 7, 2018 08:49
@charlesjhongc charlesjhongc changed the title Configurable buffer size & Add cleanUp function Refine event listener May 7, 2018
@charlesjhongc charlesjhongc force-pushed the Refine-event-listener branch from 0307be4 to c5ea00a Compare May 8, 2018 01:42
@charlesjhongc charlesjhongc force-pushed the Refine-event-listener branch from c5ea00a to 0c10c57 Compare May 8, 2018 01:49
}

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 {
Copy link
Contributor

@tailingchen tailingchen May 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return eventCh <-chan *ContractEvent?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But Listen() will be blocked until listening service terminated.

Copy link
Author

@charlesjhongc charlesjhongc May 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So how could caller access eventCh? It's a private variable.

el.eventCh <- cEvent
}
}
close(el.eventCh)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we don't wait until the events are processed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So how could caller access eventCh? It's a private variable.

@charlesjhongc
Copy link
Author

charlesjhongc commented May 11, 2018

Goal

  • shutdown gracefully
  • configurable channel size (both for eventCh and logCh)

eventCh

The 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants