-
Notifications
You must be signed in to change notification settings - Fork 35
Open
Labels
enhancementNew feature or requestNew feature or request
Description
On JVM the AtomicReference class contains the getAndUpdate() method. It'd be convenient to have it for other targets/common code as well. The non-JVM implementation can look like:
fun getAndUpdate(updateFunction: (V) -> V): V {
while(true) {
val prev = get()
val next = updateFunction(prev)
if (compareAndSet(prev, next)) return prev
}
}The signature of the corresponding JVM method is:
public final V getAndUpdate(UnaryOperator<V> updateFunction)where UnaryOperator is a functional interface:
@FunctionalInterface
public interface UnaryOperator<T> extends Function<T, T>That should place nicely with the SAM conversion
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request