@@ -67,15 +67,15 @@ public class Gauge<NumType: Numeric, Labels: MetricLabels>: Metric, PrometheusHa
67
67
/// - amount: Amount to set the gauge to
68
68
/// - labels: Labels to attach to the value
69
69
///
70
- /// - Returns: The new value
71
- @discardableResult
72
- public func set( _ amount: NumType , _ labels: Labels ? = nil ) -> NumType {
70
+ public func set( _ amount: NumType , _ labels: Labels ? = nil , _ done: @escaping ( NumType ) -> Void = { _ in } ) {
71
+ prometheusQueue. async ( flags: . barrier) {
73
72
if let labels = labels {
74
73
self . metrics [ labels] = amount
75
- return amount
74
+ done ( amount)
76
75
} else {
77
76
self . value = amount
78
- return self . value
77
+ done ( self . value)
78
+ }
79
79
}
80
80
}
81
81
@@ -85,17 +85,17 @@ public class Gauge<NumType: Numeric, Labels: MetricLabels>: Metric, PrometheusHa
85
85
/// - amount: Amount to increment the Gauge with
86
86
/// - labels: Labels to attach to the value
87
87
///
88
- /// - Returns: The new value
89
- @discardableResult
90
- public func inc( _ amount: NumType , _ labels: Labels ? = nil ) -> NumType {
88
+ public func inc( _ amount: NumType , _ labels: Labels ? = nil , _ done: @escaping ( NumType ) -> Void = { _ in } ) {
89
+ prometheusQueue. async ( flags: . barrier) {
91
90
if let labels = labels {
92
- var val = self . metrics [ labels] ?? initialValue
91
+ var val = self . metrics [ labels] ?? self . initialValue
93
92
val += amount
94
93
self . metrics [ labels] = val
95
- return val
94
+ done ( val)
96
95
} else {
97
96
self . value += amount
98
- return self . value
97
+ done ( self . value)
98
+ }
99
99
}
100
100
}
101
101
@@ -104,10 +104,10 @@ public class Gauge<NumType: Numeric, Labels: MetricLabels>: Metric, PrometheusHa
104
104
/// - Parameters:
105
105
/// - labels: Labels to attach to the value
106
106
///
107
- /// - Returns: The new value
108
- @ discardableResult
109
- public func inc ( _ labels : Labels ? = nil ) -> NumType {
110
- return self . inc ( 1 , labels )
107
+ public func inc ( _ labels : Labels ? = nil , _ done : @escaping ( NumType ) -> Void = { _ in } ) {
108
+ self . inc ( 1 , labels ) {
109
+ done ( $0 )
110
+ }
111
111
}
112
112
113
113
/// Decrements the Gauge
@@ -116,17 +116,17 @@ public class Gauge<NumType: Numeric, Labels: MetricLabels>: Metric, PrometheusHa
116
116
/// - amount: Amount to decrement the Gauge with
117
117
/// - labels: Labels to attach to the value
118
118
///
119
- /// - Returns: The new value
120
- @discardableResult
121
- public func dec( _ amount: NumType , _ labels: Labels ? = nil ) -> NumType {
119
+ public func dec( _ amount: NumType , _ labels: Labels ? = nil , _ done: @escaping ( NumType ) -> Void = { _ in } ) {
120
+ prometheusQueue. async ( flags: . barrier) {
122
121
if let labels = labels {
123
- var val = self . metrics [ labels] ?? initialValue
122
+ var val = self . metrics [ labels] ?? self . initialValue
124
123
val -= amount
125
124
self . metrics [ labels] = val
126
- return val
125
+ done ( val)
127
126
} else {
128
127
self . value -= amount
129
- return self . value
128
+ done ( self . value)
129
+ }
130
130
}
131
131
}
132
132
@@ -135,10 +135,10 @@ public class Gauge<NumType: Numeric, Labels: MetricLabels>: Metric, PrometheusHa
135
135
/// - Parameters:
136
136
/// - labels: Labels to attach to the value
137
137
///
138
- /// - Returns: The new value
139
- @ discardableResult
140
- public func dec ( _ labels : Labels ? = nil ) -> NumType {
141
- return self . dec ( 1 , labels )
138
+ public func dec ( _ labels : Labels ? = nil , _ done : @escaping ( NumType ) -> Void = { _ in } ) {
139
+ self . dec ( 1 , labels ) {
140
+ done ( $0 )
141
+ }
142
142
}
143
143
144
144
/// Gets the value of the Gauge
0 commit comments