Skip to content

Commit

Permalink
pangpanglabs#13 Use the goroutine parameter to avoid data race
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoxinmiao committed Sep 16, 2018
1 parent 428b5ca commit 82decd1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
echosample
*.db
tmp
tmp
*.test
*.exe
10 changes: 5 additions & 5 deletions models/discount.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,24 @@ func (Discount) GetAll(ctx context.Context, sortby, order []string, offset, limi
}

errc := make(chan error)
go func() {
v, err := queryBuilder().Count(&Discount{})
go func(session xorm.Interface) {
v, err := session.Count(&Discount{})
if err != nil {
errc <- err
return
}
totalCount = v
errc <- nil

}()
}(queryBuilder())

go func() {
go func(session xorm.Interface) {
if err := queryBuilder().Limit(limit, offset).Find(&items); err != nil {
errc <- err
return
}
errc <- nil
}()
}(queryBuilder())

if err := <-errc; err != nil {
return 0, nil, err
Expand Down

0 comments on commit 82decd1

Please sign in to comment.