Created
August 9, 2016 00:15
-
-
Save tuulos/9452b7a41bb3a067d9457ba01f58378f to your computer and use it in GitHub Desktop.
Reproduce tdb.close() issue in Go. Comment out db.Close() to make this work.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"os" | |
"sync" | |
"github.com/traildb/traildb-go" | |
) | |
var NUM_WORKERS = 16 | |
func worker(paths chan string, group *sync.WaitGroup) { | |
for path := range paths { | |
db, err := tdb.Open(path) | |
if err != nil { | |
panic(err) | |
} | |
trail, err := tdb.NewCursor(db) | |
if err != nil { | |
panic(err) | |
} | |
for i := uint64(0); i < db.NumTrails; i++ { | |
tdb.GetTrail(trail, i) | |
for { | |
event := trail.NextEvent() | |
if event == nil { | |
break | |
} | |
} | |
} | |
trail.Close() | |
db.Close() | |
} | |
group.Done() | |
} | |
func main() { | |
paths := make(chan string, len(os.Args) - 1) | |
for _, path := range os.Args[1:] { | |
paths <- path | |
} | |
close(paths) | |
var workers sync.WaitGroup | |
for i := 0; i < NUM_WORKERS; i++ { | |
workers.Add(1) | |
go worker(paths, &workers) | |
} | |
workers.Wait() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment