eth/filter, event: minor fixes

This commit is contained in:
rjl493456442 2018-05-09 15:57:32 +08:00
parent f11ac1eccc
commit dec5843fed
2 changed files with 5 additions and 4 deletions

View file

@ -136,7 +136,7 @@ func NewEventSystem(mux *event.TypeMux, backend Backend, lightMode bool) *EventS
// TODO(rjl493456442): use feed to subscribe pending log event
m.pendingLogSub = m.mux.Subscribe(core.PendingLogsEvent{})
// Make sure all the subscriptions are not empty
// Make sure none of the subscriptions are empty
if m.txSub == nil || m.logsSub == nil || m.rmLogsSub == nil || m.chainSub == nil ||
m.pendingLogSub.Closed() {
log.Crit("Subscribe for event system failed")
@ -442,10 +442,8 @@ func (es *EventSystem) lightFilterLogs(header *types.Header, addresses []common.
// eventLoop (un)installs filters and processes mux events.
func (es *EventSystem) eventLoop() {
var index = make(filterIndex)
// Ensure all subscriptions get cleaned up
defer func() {
// Unsubscribe all events
es.pendingLogSub.Unsubscribe()
es.txSub.Unsubscribe()
es.logsSub.Unsubscribe()
@ -453,6 +451,7 @@ func (es *EventSystem) eventLoop() {
es.chainSub.Unsubscribe()
}()
index := make(filterIndex)
for i := UnknownSubscription; i < LastIndexSubscription; i++ {
index[i] = make(map[rpc.ID]*subscription)
}

View file

@ -181,6 +181,8 @@ func (s *TypeMuxSubscription) Unsubscribe() {
}
func (s *TypeMuxSubscription) Closed() bool {
s.closeMu.Lock()
defer s.closeMu.Unlock()
return s.closed
}