Skip to content

Commit

Permalink
removed unused struct and refacto for { select { } } according to linter
Browse files Browse the repository at this point in the history
  • Loading branch information
eze-kiel committed Apr 7, 2021
1 parent a2c8151 commit b84e6e9
Showing 1 changed file with 16 additions and 25 deletions.
41 changes: 16 additions & 25 deletions cmd/slowql-replayer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ type results struct {
realDuration time.Duration
}

type job struct {
idle time.Duration
query string
}

func main() {
var opt options

Expand Down Expand Up @@ -429,33 +424,29 @@ func newSpinner(t int) *spinner.Spinner {
func (db database) worker(queries chan string, errors chan error, wg *sync.WaitGroup) {
defer wg.Done()
for {
select {
case q, ok := <-queries:
if !ok {
db.logger.Trace("channel closed, worker exiting")
return
}
rows, err := db.drv.Query(q)
if err != nil {
errors <- err
db.logger.Debugf("failed to execute query:\n%s\nerror: %s", q, err)
}
if rows != nil {
rows.Close()
}
q, ok := <-queries
if !ok {
db.logger.Trace("channel closed, worker exiting")
return
}
rows, err := db.drv.Query(q)
if err != nil {
errors <- err
db.logger.Debugf("failed to execute query:\n%s\nerror: %s", q, err)
}
if rows != nil {
rows.Close()
}
}
}

func (r *results) errorsCollector(errors chan error) {
for {
select {
case _, ok := <-errors:
if !ok {
return
}
r.errors++
_, ok := <-errors
if !ok {
return
}
r.errors++
}
}

Expand Down

0 comments on commit b84e6e9

Please sign in to comment.