- 解决wxtoken的刷新问题
This commit is contained in:
@@ -33,7 +33,6 @@ const (
|
||||
)
|
||||
|
||||
type IEventProducer interface {
|
||||
GetEvent(eventTypeList []string, criteria interface{}) (event *EventInfo, err error)
|
||||
IsCriteriaMatch(eventInfo *EventInfo, criteria interface{}) bool
|
||||
}
|
||||
|
||||
@@ -212,36 +211,29 @@ func (e *EventHub) PostNewEvent(eventCategory string, event *EventInfo) {
|
||||
}
|
||||
|
||||
func (e *EventHub) GetEvent(eventCategory string, eventTypeList []string, criteria interface{}, waitTime time.Duration) (event *EventInfo, err error) {
|
||||
eventProducer := e.getEventProducer(eventCategory)
|
||||
if eventProducer == nil {
|
||||
return nil, fmt.Errorf("eventCategory:%s没有注册", eventCategory)
|
||||
}
|
||||
event, err = eventProducer.GetEvent(eventTypeList, criteria)
|
||||
if err == nil && event == nil {
|
||||
notifyChan := e.registerConsumer(eventCategory, eventTypeList, criteria)
|
||||
pollingDuration := defPollingDuration
|
||||
if waitTime != 0 {
|
||||
pollingDuration = waitTime
|
||||
if globals.IsProductEnv() {
|
||||
if pollingDuration > maxPollingDuration {
|
||||
pollingDuration = maxPollingDuration
|
||||
} else if pollingDuration < minPollingDuration {
|
||||
pollingDuration = minPollingDuration
|
||||
}
|
||||
notifyChan := e.registerConsumer(eventCategory, eventTypeList, criteria)
|
||||
pollingDuration := defPollingDuration
|
||||
if waitTime != 0 {
|
||||
pollingDuration = waitTime
|
||||
if globals.IsProductEnv() {
|
||||
if pollingDuration > maxPollingDuration {
|
||||
pollingDuration = maxPollingDuration
|
||||
} else if pollingDuration < minPollingDuration {
|
||||
pollingDuration = minPollingDuration
|
||||
}
|
||||
}
|
||||
timer := time.NewTimer(pollingDuration)
|
||||
select {
|
||||
case tmpEvent, ok := <-notifyChan:
|
||||
timer.Stop()
|
||||
if ok {
|
||||
event = tmpEvent
|
||||
}
|
||||
case <-timer.C:
|
||||
e.unregisterConsumer(notifyChan)
|
||||
}
|
||||
close(notifyChan)
|
||||
}
|
||||
timer := time.NewTimer(pollingDuration)
|
||||
select {
|
||||
case tmpEvent, ok := <-notifyChan:
|
||||
timer.Stop()
|
||||
if ok {
|
||||
event = tmpEvent
|
||||
}
|
||||
case <-timer.C:
|
||||
e.unregisterConsumer(notifyChan)
|
||||
}
|
||||
close(notifyChan)
|
||||
return event, err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user