Browse Source

Code comments, fix tests, lint

Vova Tkach 5 years ago
parent
commit
5df5e6e068
2 changed files with 9 additions and 4 deletions
  1. 7 0
      main.go
  2. 2 4
      worker/worker_test.go

+ 7 - 0
main.go

@@ -44,14 +44,21 @@ func main() {
 		w.Shutdown(nil)
 	}, nil)
 
+	// Just wait for goroutines
 	time.Sleep(3 * time.Second)
 
+	// Shutdown first
+	// Normally, it's must be used with context
 	w1.Shutdown(nil)
 
+	// Shutdown second
+	// Normally, it's must be used with context
 	if err := w2.Shutdown(nil); err != nil {
 		fmt.Printf("Worker #2 shutdown error: %s\n", err.Error())
 	}
 
+	// Wait for third
+	// Will be exited automatically
 	time.Sleep(1 * time.Second)
 
 	fmt.Printf("End!\n")

+ 2 - 4
worker/worker_test.go

@@ -1,10 +1,10 @@
 package worker
 
 import (
-	"time"
-	"errors"
 	"context"
+	"errors"
 	"testing"
+	"time"
 )
 
 type SomeTest struct {
@@ -29,8 +29,6 @@ func compareResults(v *SomeTest) (bool, error) {
 	case <-v.Done:
 		return v.Variable, worker.Shutdown(nil)
 	}
-
-	return v.Variable, worker.Shutdown(nil)
 }
 
 func TestGoroutineAndChangeVariable(t *testing.T) {