From 7d59a98f90941167660ec5b5aa32ba2da4e70df7 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 22 Jun 2021 09:02:40 +0200 Subject: [PATCH] Add missing doc in utils --- pkg/utils/utils.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 8c25adf5..74d33bfe 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -65,10 +65,21 @@ func Key(name string, sep byte) string { return b.String() } +// Timed calls the given callback with the time that has elapsed since the start. +// +// Timed should be installed by defer: +// +// func TimedExample(logger *zap.SugaredLogger) { +// defer utils.Timed(time.Now(), func(elapsed time.Duration) { +// logger.Debugf("Executed job in %s", elapsed) +// }) +// job() +// } func Timed(start time.Time, callback func(elapsed time.Duration)) { callback(time.Since(start)) } +// BatchSliceOfStrings groups the given keys into chunks of size count and streams them into a returned channel. func BatchSliceOfStrings(ctx context.Context, keys []string, count int) <-chan []string { batches := make(chan []string) @@ -92,10 +103,12 @@ func BatchSliceOfStrings(ctx context.Context, keys []string, count int) <-chan [ return batches } +// IsContextCanceled returns whether the given error is context.Canceled. func IsContextCanceled(err error) bool { return errors.Is(err, context.Canceled) } +// Checksum returns the SHA-1 checksum of the data. func Checksum(data interface{}) []byte { var chksm [sha1.Size]byte @@ -111,8 +124,8 @@ func Checksum(data interface{}) []byte { return chksm[:] } +// Fatal panics with the given error. func Fatal(err error) { - // TODO(el): Print stacktrace via some recover() magic? panic(err) }