summaryrefslogtreecommitdiff
path: root/internal/clients/handlers/withcancel.go
blob: 7c9cf4e2f68654822d889b60001f0a046c38d717 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package handlers

import "context"

type withCancel struct {
	ctx  context.Context
	done chan struct{}
}

// WithCancel sets and returns the context used.
func (w *withCancel) WithCancel(ctx context.Context) (context.Context, context.CancelFunc) {
	cancelCtx, cancel := context.WithCancel(ctx)
	w.ctx = cancelCtx

	return cancelCtx, cancel
}

func (w *withCancel) Done() <-chan struct{} {
	return w.done
}

func (w *withCancel) shutdown() {
	close(w.done)
}