From ce15b43db3e60acc65ddd25de253b8577c2693aa Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期三, 08 五月 2019 14:11:03 +0800
Subject: [PATCH] context使用

---
 analysis/work/service/ipcreciever.go |   27 +++++----------------------
 1 files changed, 5 insertions(+), 22 deletions(-)

diff --git a/analysis/work/service/ipcreciever.go b/analysis/work/service/ipcreciever.go
index 68e1147..a008a15 100644
--- a/analysis/work/service/ipcreciever.go
+++ b/analysis/work/service/ipcreciever.go
@@ -10,7 +10,7 @@
 
 // Reciever recv from ipc
 type Reciever struct {
-	ctxIPC  *ContextIPC
+	ctx     context.Context
 	ipcURL  string
 	chImage chan<- ImageInfo
 }
@@ -34,20 +34,10 @@
 }
 
 // NewReciever new recv
-func NewReciever(url string, ch chan<- ImageInfo) *Reciever {
-	ctx, cancel := context.WithCancel(context.Background())
+func NewReciever(ctx context.Context, url string, ch chan<- ImageInfo) *Reciever {
 
 	return &Reciever{
-		ctxIPC:  &ContextIPC{ctx, cancel},
-		ipcURL:  url,
-		chImage: ch,
-	}
-}
-
-// NewRecieverWithContext new recver with context
-func NewRecieverWithContext(ctx context.Context, url string, ch chan<- ImageInfo) *Reciever {
-	return &Reciever{
-		ctxIPC:  &ContextIPC{ctx, nil},
+		ctx:     ctx,
 		ipcURL:  url,
 		chImage: ch,
 	}
@@ -62,18 +52,11 @@
 
 // RunAsServer run a IPC server
 func (r *Reciever) RunAsServer() {
-	r.run(ipc.NewServer(r.ctxIPC.ctx, r.ipcURL))
+	r.run(ipc.NewServer(r.ctx, r.ipcURL))
 
 }
 
 // RunAsClient run as a IPC client
 func (r *Reciever) RunAsClient() {
-	r.run(ipc.NewClient(r.ctxIPC.ctx, r.ipcURL))
-}
-
-// Stop stop reciever, run in goroutine
-func (r *Reciever) Stop() {
-	if r.ctxIPC.cancel != nil {
-		r.ctxIPC.cancel()
-	}
+	r.run(ipc.NewClient(r.ctx, r.ipcURL))
 }

--
Gitblit v1.8.0