core/cmd/twhelp/utils.go

35 lines
683 B
Go

package main
import (
"context"
"os"
"os/signal"
"syscall"
)
func concatSlices[T any](slices ...[]T) []T {
var totalLen int
for _, s := range slices {
totalLen += len(s)
}
result := make([]T, totalLen)
var i int
for _, s := range slices {
i += copy(result[i:], s)
}
return result
}
var shutdownSignals = []os.Signal{os.Interrupt, syscall.SIGTERM}
// newShutdownSignalContext returns a copy of the parent context that is marked done
// (its Done channel is closed) when one of the shutdownSignals arrives.
func newShutdownSignalContext(parent context.Context) (context.Context, context.CancelFunc) {
return signal.NotifyContext(parent, shutdownSignals...)
}