summaryrefslogtreecommitdiff
path: root/internal/done.go
diff options
context:
space:
mode:
authorPaul Buetow <pbuetow@mimecast.com>2020-09-19 19:53:03 +0100
committerPaul Buetow <pbuetow@mimecast.com>2020-09-19 19:53:03 +0100
commitf7849d259668b408829f2b2e8d29b9753eff390a (patch)
tree2e1dcee66abeef22a12c27e7a633baa27f2773fe /internal/done.go
parentcdbcef72a1b9f93d08455b5a77f7f7afa2b9f53d (diff)
parent3c889d2eed4e12af505ea84d46d8e52d21057a1f (diff)
Merge branch 'develop' of https://github.com/mimecast/dtail into develop
Diffstat (limited to 'internal/done.go')
-rw-r--r--internal/done.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/internal/done.go b/internal/done.go
new file mode 100644
index 0000000..2326eee
--- /dev/null
+++ b/internal/done.go
@@ -0,0 +1,32 @@
+package internal
+
+import (
+ "sync"
+)
+
+type Done struct {
+ ch chan struct{}
+ mutex sync.Mutex
+}
+
+func NewDone() *Done {
+ return &Done{
+ ch: make(chan struct{}),
+ }
+}
+
+func (d *Done) Done() <-chan struct{} {
+ return d.ch
+}
+
+func (d *Done) Shutdown() {
+ d.mutex.Lock()
+ defer d.mutex.Unlock()
+
+ select {
+ case <-d.ch:
+ return
+ default:
+ close(d.ch)
+ }
+}