diff options
| author | Paul Buetow <pbuetow@mimecast.com> | 2020-09-19 19:53:03 +0100 |
|---|---|---|
| committer | Paul Buetow <pbuetow@mimecast.com> | 2020-09-19 19:53:03 +0100 |
| commit | f7849d259668b408829f2b2e8d29b9753eff390a (patch) | |
| tree | 2e1dcee66abeef22a12c27e7a633baa27f2773fe /internal/done.go | |
| parent | cdbcef72a1b9f93d08455b5a77f7f7afa2b9f53d (diff) | |
| parent | 3c889d2eed4e12af505ea84d46d8e52d21057a1f (diff) | |
Merge branch 'develop' of https://github.com/mimecast/dtail into develop
Diffstat (limited to 'internal/done.go')
| -rw-r--r-- | internal/done.go | 32 |
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) + } +} |
