浏览代码

更新 注释

dcsunny 4 年之前
父节点
当前提交
a399afbb9c
共有 1 个文件被更改,包括 3 次插入16 次删除
  1. 3 16
      common/global_wait_group.go

+ 3 - 16
common/global_wait_group.go

@@ -13,11 +13,9 @@ import (
 )
 
 func main() {
-	ctx := context.Background()
-	common.GlobalWaitGroup.SetContext(ctx)
 	test()
 	go test()
-	common.GlobalWaitGroup.Wait()
+	common.GlobalWaitGroup.Stop()
 }
 
 func test() {
@@ -38,7 +36,6 @@ func test() {
 */
 
 import (
-	"context"
 	"fmt"
 	"sync"
 	"time"
@@ -47,37 +44,27 @@ import (
 var GlobalWaitGroup *globalWaitGroup
 
 func init() {
-	GlobalWaitGroup = NewGlobalWaitGroup(context.Background())
+	GlobalWaitGroup = NewGlobalWaitGroup()
 }
 
 type globalWaitGroup struct {
 	wg      sync.WaitGroup
-	ctx     context.Context
 	timeout int64 //超时时间, 时间戳
 	isStop  bool
 	lock    sync.Mutex
 	ok      chan bool
 }
 
-func NewGlobalWaitGroup(ctx context.Context) *globalWaitGroup {
+func NewGlobalWaitGroup() *globalWaitGroup {
 	this := &globalWaitGroup{
 		wg:     sync.WaitGroup{},
-		ctx:    ctx,
 		isStop: false,
 		ok:     make(chan bool, 1),
 	}
-	go func() {
-		<-this.ctx.Done()
-		this.isStop = true
-	}()
 
 	return this
 }
 
-func (this *globalWaitGroup) SetContext(ctx context.Context) {
-	this.ctx, _ = context.WithCancel(ctx)
-}
-
 func (this *globalWaitGroup) Stop() {
 	this.isStop = true
 	this.Wait()