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
commitdf29de727c814051e1adac7082760427878c4874 (patch)
tree2e1dcee66abeef22a12c27e7a633baa27f2773fe /internal/done.go
parenta9b2bf6b7caaf207bf11a99aa4f68ae8ee7f1746 (diff)
parent6015ff9509ae6dc391d997a047dbe9f0b5095c78 (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)
+ }
+}