summaryrefslogtreecommitdiff
path: root/internal/done.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@dionysus>2020-09-19 18:38:36 +0100
committerPaul Buetow <paul@dionysus>2020-09-19 18:38:36 +0100
commitbad8e04bb4410b94b8e875ccde287f74ab94121a (patch)
tree9fb8f7aea4e240e5de49acd4e6fd18c5a0282b57 /internal/done.go
parent813d2d00ec581c801d64091c7774988b559c3e93 (diff)
server handler context refactoring
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)
+ }
+}