MCPcopy Create free account
hub / github.com/Effect-TS/effect / counter

Function counter

packages/effect/src/internal/metric/hook.ts:80–99  ·  view source on GitHub ↗
(
  key: MetricKey.MetricKey.Counter<A>
)

Source from the content-addressed store, hash-verified

78
79/** @internal */
80export const counter = <A extends (number | bigint)>(
81 key: MetricKey.MetricKey.Counter<A>
82): MetricHook.MetricHook.Counter<A> => {
83 let sum: A = key.keyType.bigint ? bigint0 as A : 0 as A
84 const canUpdate = key.keyType.incremental
85 ? key.keyType.bigint
86 ? (value: A) => value >= bigint0
87 : (value: A) => value >= 0
88 : (_value: A) => true
89 const update = (value: A) => {
90 if (canUpdate(value)) {
91 sum = (sum as any) + value
92 }
93 }
94 return make({
95 get: () => metricState.counter(sum as number) as unknown as MetricState.MetricState.Counter<A>,
96 update,
97 modify: update
98 })
99}
100
101/** @internal */
102export const frequency = (key: MetricKey.MetricKey.Frequency): MetricHook.MetricHook.Frequency => {

Callers

nothing calls this directly

Calls 1

makeFunction · 0.70

Tested by

no test coverage detected