Skip to content

Commit

Permalink
use conc.WaitGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
batazor committed Jan 8, 2023
1 parent aab05f4 commit 2e96c9f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
25 changes: 12 additions & 13 deletions .run/shortdb_ engine.run.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="shortdb: engine" type="GoTestRunConfiguration" factoryName="Go Test"
folderName="test/shortdb">
<module name="shortlink"/>
<working_directory value="$PROJECT_DIR$/pkg/shortdb/engine"/>
<go_parameters value="-race"/>
<root_directory value="$PROJECT_DIR$"/>
<kind value="PACKAGE"/>
<package value="github.com/shortlink-org/shortlink/pkg/shortdb/engine"/>
<directory value="$PROJECT_DIR$"/>
<filePath value="$PROJECT_DIR$"/>
<framework value="gotest"/>
<method v="2"/>
<configuration default="false" name="shortdb: engine" type="GoTestRunConfiguration" factoryName="Go Test" folderName="test/shortdb">
<module name="shortlink" />
<working_directory value="$PROJECT_DIR$/pkg/shortdb/engine" />
<go_parameters value="-tags=unit" />
<root_directory value="$PROJECT_DIR$" />
<kind value="PACKAGE" />
<package value="github.com/shortlink-org/shortlink/pkg/shortdb/engine" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$" />
<framework value="gotest" />
<method v="2" />
</configuration>
</component>
</component>
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ require (
github.com/robfig/cron/v3 v3.0.1
github.com/segmentio/encoding v0.3.6
github.com/sirupsen/logrus v1.9.0
github.com/sourcegraph/conc v0.1.0
github.com/spf13/cobra v1.6.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.14.0
Expand Down
4 changes: 2 additions & 2 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,6 @@ github.com/coreos/go-etcd v2.0.0+incompatible h1:bXhRBIXoTm9BYHS3gE0TtQuyNZyeEMu
github.com/coreos/go-iptables v0.6.0 h1:is9qnZMPYjLd8LYqmm/qlE+wwEgJIkTYdhV3rfZo4jk=
github.com/coreos/go-oidc v2.1.0+incompatible h1:sdJrfw8akMnCuUlaZU3tE/uYXFgfqom8DBE9so9EBsM=
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f h1:lBNOc5arjvs8E5mO2tbpBpLoyyu8B6e44T7hJy6potg=
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cznic/mathutil v0.0.0-20180504122225-ca4c9f2c1369 h1:XNT/Zf5l++1Pyg08/HV04ppB0gKxAqtZQBRYiYrUuYk=
github.com/d2g/dhcp4 v0.0.0-20170904100407-a1d1b6c41b1c h1:Xo2rK1pzOm0jO6abTPIQwbAmqBIOj132otexc1mmzFc=
github.com/d2g/dhcp4client v1.0.0 h1:suYBsYZIkSlUMEz4TAYCczKf62IA2UWC+O8+KtdOhCo=
Expand Down Expand Up @@ -884,7 +883,8 @@ github.com/snowflakedb/glog v0.0.0-20180824191149-f5055e6f21ce h1:CGR1hXCOeoZ1aJ
github.com/snowflakedb/gosnowflake v1.6.3 h1:EJDdDi74YbYt1ty164ge3fMZ0eVZ6KA7b1zmAa/wnRo=
github.com/soheilhy/cmux v0.1.5 h1:jjzc5WVemNEDTLwv9tlmemhC73tI08BNOIGwBOo10Js=
github.com/sony/gobreaker v0.4.1 h1:oMnRNZXX5j85zso6xCPRNPtmAycat+WcoKbklScLDgQ=
github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g=
github.com/sourcegraph/conc v0.1.0 h1:9GeYVmWWa1jeOq3zGq17m10d9pjYZpiGTj/N4hQFl58=
github.com/sourcegraph/conc v0.1.0/go.mod h1:sEXGtKMpRbfGhShfObhgMyxDpdu/5ABGrzSGYaigx5A=
github.com/spf13/cobra v1.6.0/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
github.com/stefanberger/go-pkcs11uri v0.0.0-20201008174630-78d3cae3a980 h1:lIOOHPEbXzO3vnmx2gok1Tfs31Q8GQqKLc8vVqyQq/I=
github.com/stoewer/go-strcase v1.2.0 h1:Z2iHWqGXH00XYgqDmNgQbIBxf3wrNq0F3feEy0ainaU=
Expand Down
14 changes: 7 additions & 7 deletions pkg/shortdb/engine/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"sync"

"github.com/sourcegraph/conc"
"github.com/spf13/viper"
"google.golang.org/protobuf/proto"

Expand Down Expand Up @@ -121,13 +122,13 @@ func (f *file) init() error {
}()

payload := []byte{}
var wg sync.WaitGroup
wg.Add(1)
var wg conc.WaitGroup

// Read a file.
err = io_uring.ReadFile(fileOpenFile.Name(), func(buf []byte) {
payload = buf
wg.Done()
wg.Go(func() {
payload = buf
})
})
if err != nil {
return err
Expand Down Expand Up @@ -172,8 +173,7 @@ func (f *file) Close() error {
}
}()

var wg sync.WaitGroup
wg.Add(1)
var wg conc.WaitGroup

// save last page
for tableName := range f.database.Tables {
Expand All @@ -196,7 +196,7 @@ func (f *file) Close() error {

// save database
err = io_uring.WriteFile(databaseFile.Name(), payload, 0o644, func(n int) { // nolint:gomnd
defer wg.Done()
wg.Go(func() {})
// handle n
})
if err != nil {
Expand Down

0 comments on commit 2e96c9f

Please sign in to comment.