houseofcat / turbocookedrabbit

A user friendly RabbitMQ library written in Golang.
MIT License
107 stars 20 forks source link

Acquire lock before fetch Started, to prevent data-race #28

Closed Cdayz closed 2 years ago

Cdayz commented 2 years ago

Hi, now i am working on library which are rely on this. I want to close all my library channels only after consumer really stop consuming loop. For example:

err := consuming.consumer.StopConsuming(immediately, flushMessages)
if err != nil {
    return errors.WithMessage(err, "stop consumer")
}

// NOTE: do not close output channel while underlying consumer really stops
for consuming.consumer.Started() {
    time.Sleep(10 * time.Millisecond)
}

close(consuming.outputChan)

And now, when i run tests, i've got a data-race, because i want to read variable Started, and at the same time this variable changed by consumer.