Skip to content

Conditional update

Atomically sets the value to the given updated value if the current value == the expected value.

Future<bool> Backendless.counters.compareAndSet(String counterName, int expected, int updated);

IAtomic counter = Backendless.counters.of(String counterName);
Future<bool> counter.compareAndSet(int expected, int updated);


Argument                Description
counterName name of the counter to compare.
expected the expected value of the counter. If the current value equals the expected value, the counter is set to the "updated" value.
updated the new value to assign to the counter if the current value equals the expected value.


Function callback = (result) => print("value has been updated - $result");

Backendless.counters.compareAndSet("my counter", 1000, 2000).then(callback);

IAtomic myCounter = Backendless.counters.of("my counter");
myCounter.compareAndSet(1000, 2000).then(callback);