Browse Source

Add signal notify hook for run group quiter.

ZRY 1 year ago
parent
commit
9477d49516
4 changed files with 31 additions and 4 deletions
  1. 9 0
      .idea/go-lazy-quiter.iml
  2. 8 0
      .idea/modules.xml
  3. 6 0
      .idea/vcs.xml
  4. 8 4
      run-group-quiter.go

+ 9 - 0
.idea/go-lazy-quiter.iml

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="WEB_MODULE" version="4">
+  <component name="Go" enabled="true" />
+  <component name="NewModuleRootManager">
+    <content url="file://$MODULE_DIR$" />
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+</module>

+ 8 - 0
.idea/modules.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/.idea/go-lazy-quiter.iml" filepath="$PROJECT_DIR$/.idea/go-lazy-quiter.iml" />
+    </modules>
+  </component>
+</project>

+ 6 - 0
.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="" vcs="Git" />
+  </component>
+</project>

+ 8 - 4
run-group-quiter.go

@@ -7,9 +7,10 @@ import (
 )
 
 type RunGroupQuiter struct {
-	qchan chan os.Signal
-	ctx   context.Context
-	cncl  context.CancelFunc
+	qchan            chan os.Signal
+	ctx              context.Context
+	cncl             context.CancelFunc
+	SignalNotifyFunc func(sig os.Signal)
 }
 
 func NewRunGroupQuiter(sig ...os.Signal) *RunGroupQuiter {
@@ -32,11 +33,14 @@ func (q *RunGroupQuiter) Run() error {
 			close(q.qchan)
 			return nil
 		}
-	case <-q.qchan:
+	case sig := <-q.qchan:
 		{
 			if q.cncl != nil {
 				q.cncl()
 			}
+			if q.SignalNotifyFunc != nil {
+				q.SignalNotifyFunc(sig)
+			}
 			return nil
 		}
 	}