updateAndGet method

T updateAndGet(
  1. T updater(
    1. T current
    )
)

Applies the updater function to the current value, sets the result, and returns the new value.

final newValue = counter.updateAndGet((current) => current * 2);
print(newValue); // 10

Implementation

T updateAndGet(T Function(T current) updater) {
  final newValue = updater(value);
  value = newValue;
  return newValue;
}