diff options
| author | Paul Buetow <35781042+pbuetow@users.noreply.github.com> | 2020-09-19 19:52:11 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-09-19 19:52:11 +0100 |
| commit | 6015ff9509ae6dc391d997a047dbe9f0b5095c78 (patch) | |
| tree | 8e6d9f697fe9a5c70f200d54745bb5daecac6bde /internal/done.go | |
| parent | 4bcc6d68844001b41d615aa01bacf580669af1c4 (diff) | |
| parent | 2dba2f71a17faf9ed5d5dc4eafa3440e0dbc45f6 (diff) | |
Merge pull request #14 from snonux/develop
Refactor context handling
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) + } +} |
