I have been trying to reuse a the prepared query in concurrent calls.
type product struct {
query *gocql.Query
}
type resp struct {
Pk string
Product Product
Err error
}
func (p *product) A() {
...
respFromDB := make(chan resp, len(pks))
for _, pk := range pks {
go p.getAll(pk, resp)
}
}
func (p *product) getAll(pk string, product chan resp) {
var (
err error
prodResp resp
)
prod := Product{}
prodResp = resp{
Pk: pk,
}
err = p.preparedStatement.Bind(gtin13).Scan(&prod.Pk,...)
if err != nil {
prodResp.Err = err
product <- prodResp
return
}
prodResp.Product = prod
product <- prodResp
}
The pks are being passed to getAll function but the Bind function seems to not be bind every pk to the corresponding call.
Instead the some pk is being repeatedly binded.
Is there something wrong in this approach? Not sure why the pks are being binded to the corresponding calls.
The Query is created once in the main and injected for all further calls.