Increment by N, return current¶
Atomically adds the given value to the current value and returns the updated (current) value of the counter. Multiple concurrent client requests are guaranteed to return updated value.
- (void)addAndGetWithCounterName:(NSString * _Nonnull)counterName value:(NSInteger)value responseHandler:^(NSInteger)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;
func addAndGet(counterName: String, value: Int, responseHandler: ((Int) -> Void)!, errorHandler: ((Fault) -> Void)!)
where:
Argument | Description |
---|---|
counterName |
name of the counter to update. |
value |
number to add to the current counter value |
Example¶
[Backendless.shared.counters addAndGetWithCounterName:@"MyCounter" value:7 responseHandler:^(NSInteger value) {
NSLog(@"Current value = %li", value);
} errorHandler:^(Fault *fault) {
NSLog(@"Error: %@", fault.message);
}];
//
id<IAtomic> myCounter = [Backendless.shared.counters ofCounterName:@"MyCounter"];
[myCounter addAndGetWithValue:7 responseHandler:^(NSInteger value) {
NSLog(@"Current value = %li", value);
} errorHandler:^(Fault *fault) {
NSLog(@"Error: %@", fault.message);
}];}
Backendless.shared.counters.addAndGet(counterName: "MyCounter", value: 7, responseHandler: { value in
print("Current value = \(value)")
}, errorHandler: { fault in
print("Error: \(fault.message ?? "")")
})
//
let myCounter = Backendless.shared.counters.of(counterName: "MyCounter")
myCounter.addAndGet(value: 7, responseHandler: { value in
print("Current value = \(value)")
}, errorHandler: { fault in
print("Error: \(fault.message ?? "")")
})
Codeless Reference¶
where:
Argument | Description |
---|---|
counter name |
Name of the counter whose value must be incremented. |
increment by |
Specify the number to increment the value by. |
return current value |
When this box is checked, the operation returns the current value of the counter. |
Returns the current value of the counter.
Consider the following counter:
The example below increments the value of the "CarsParkingLot"
by 20
. This operation returns 20
, since the return current value
box is checked.
The result of this operation will look as shown below after the Codeless logic runs: