devimteam / amqp

Golang AMQP wrapper
MIT License
10 stars 12 forks source link

Unable to cancel subscription #4

Closed matthewtsmith closed 5 years ago

matthewtsmith commented 5 years ago

Context.Done() is not being obeyed when processAll = false

Given the following example, the subscriber will not break out of the processEvent loop if either the timeout is passed or cancelFunc() is called

ctx, cancelFunc := context.WithTimeout(context.Background(), timeout)
events := subscriber.SubscribeToExchange(ctx, string(eventType), Event{}, amqp.Consumer{})
for e := range events {
    eventData := e.Data.(*Event)
    if filter == nil || filter(eventData) {
        e.Done()
        return eventData, nil
    }
    e.Done()
}
vetcher commented 5 years ago

Thank you

matthewtsmith commented 5 years ago

@vetcher Thanks for the quick release.