Marc Knaup
10/10/2020, 6:58 PMAtomicRef
and Deferred
a good approach to ensure that concurrent calls to update()
never cause more than one updateAsync()
execution in parallel?
For example let’s say updateAsync()
execution takes 10 seconds and there are 4 calls to update()
with 2 seconds in between. updateAsync()
would only be called once and they all share the same result, right?Dominaezzz
10/10/2020, 7:35 PMupdateAsync()
multiple times. (Unless it's just an illustration then nvm).
The function pass to updateAndGet
should be pure.AtomicRef
, I think you should use a Semaphore
.Marc Knaup
10/10/2020, 7:49 PMDominaezzz
10/10/2020, 7:50 PMMarc Knaup
10/10/2020, 7:51 PMDominaezzz
10/10/2020, 7:52 PMMarc Knaup
10/10/2020, 7:52 PMMutex
then?
Mutex
basically seems to be a Semaphore
with permits = 1
, doesn’t it?Dominaezzz
10/10/2020, 7:54 PMSemaphore
was quite recently optimised and currently performs better than Mutex
. (I checked this a month ago, not sure if Mutex
has been updated since).Marc Knaup
10/10/2020, 7:55 PMCasey Brooks
10/12/2020, 2:26 PMupdateAsync
is running that it won’t try to update again? Or that new updates cancel/replace the previous one? There are a handful of things you can do with Channels or Flows that can solve both those cases pretty elegantlyMarc Knaup
10/12/2020, 2:41 PMDominaezzz
10/12/2020, 2:58 PMFlow
.Marc Knaup
10/12/2020, 3:00 PMflow { while(true) { emit(update()); delay(refreshInterval) } }.stateIn(…)
Dominaezzz
10/12/2020, 3:15 PMstateIn
off course, that makes a lot of sense.