diff options
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) + } +} |
