snapshot of https://github.com/ThreeDotsLabs/watermill.git (master, 2026-09-15; blobs > 131072B omitted)
Some checks failed
master / ci (push) Failing after 0s
Some checks failed
master / ci (push) Failing after 0s
This commit is contained in:
28
components/metrics/ctx.go
Normal file
28
components/metrics/ctx.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package metrics
|
||||
|
||||
import "context"
|
||||
|
||||
type contextValue int
|
||||
|
||||
const (
|
||||
publishObserved contextValue = iota
|
||||
subscribeObserved
|
||||
)
|
||||
|
||||
// setPublishObservedToCtx is used to achieve metrics idempotency in case of double applied middleware
|
||||
func setPublishObservedToCtx(ctx context.Context) context.Context {
|
||||
return context.WithValue(ctx, publishObserved, true)
|
||||
}
|
||||
|
||||
func publishAlreadyObserved(ctx context.Context) bool {
|
||||
return ctx.Value(publishObserved) != nil
|
||||
}
|
||||
|
||||
// setSubscribeObservedToCtx is used to achieve metrics idempotency in case of double applied middleware
|
||||
func setSubscribeObservedToCtx(ctx context.Context) context.Context {
|
||||
return context.WithValue(ctx, subscribeObserved, true)
|
||||
}
|
||||
|
||||
func subscribeAlreadyObserved(ctx context.Context) bool {
|
||||
return ctx.Value(subscribeObserved) != nil
|
||||
}
|
||||
Reference in New Issue
Block a user