Hi there, I'm trying to port some usages of Atomic...
# announcements
a
Hi there, I'm trying to port some usages of AtomicInteger/Boolean/Reference to use github.com/Kotlin/kotlinx.atomicfu instead but apparently this is failing due to
factory kotlinx.atomicfu.AtomicFU::atomic is used outside of constructor or class initialisation
I'm just using them in local functions mainly, is this not permitted? if so, is there an alternative usage to do so? Thanks in advance! cc @elizarov
e
Why would you need to use them in local functions? (yes, it is not supported)
a
I got into thinking they'll work as a 1:1 mapping to Atomics from java
is there a specific technical decission for this to be like this? mostly curious now
s
We have that use-case in a lot places in Arrow. Custom stream concurrency operators for example.
☝️ 1
e
Cleate an explicit container class to keep your state.
They are not 1-on-1 mapping to atomic. They are mapping to a volatile field +
AtomicXxxFieldUpdater
(hence the name
AtomicFU
). This is more efficient (no boxes for atomics)
s
Okay, I see. So to gain that power we need to manually wrap it.
e
Yes. Or send PR to support your use-case. Don’t foreget to write tests, though 😉
s
If there is any interest for such a wrapper I’d be happy to create a PR with tests!
Thanks for the help
e
For wrapper — no. But support using them as locals — why not.
👍 2
a
thank you @elizarov