Permalink
Browse files

introduce lock to DiffCmd

  • Loading branch information...
1 parent 38d25df commit c7c984cab38c972068ff0b947ab930ed71e7d35d @haya14busa committed Dec 12, 2016
Showing with 7 additions and 1 deletion.
  1. +7 −1 diff.go
View
@@ -1,6 +1,9 @@
package reviewdog
-import "os/exec"
+import (
+ "os/exec"
+ "sync"
+)
var _ DiffService = &DiffString{}
@@ -28,6 +31,7 @@ type DiffCmd struct {
strip int
out []byte
done bool
+ mu sync.RWMutex
}
func NewDiffCmd(cmd *exec.Cmd, strip int) *DiffCmd {
@@ -36,6 +40,8 @@ func NewDiffCmd(cmd *exec.Cmd, strip int) *DiffCmd {
// Diff returns diff. It caches the result and can be used more than once.
func (d *DiffCmd) Diff() ([]byte, error) {
+ d.mu.Lock()
+ defer d.mu.Unlock()
if d.done {
return d.out, nil
}

0 comments on commit c7c984c

Please sign in to comment.