igor.wojda
10/13/2023, 12:19 AMLayer1) that are starting Big chunk of work on a single thread (Layer2) and then pass the result to another class (Layer3). Currently this chunk work is duplicated on each thread. I would like utilise coroutines to perform this Big chunk of work once on multiple threads and cache the result. Client class (Layer) can't use coroutines so these coroutines (Layer2) have to be a thread blocking call (Class no coroutines, nit suspended function).
• When a new instance of class (Layer1) wants to start work and work is already in progress (Layer2) then this (Layer1) waits for the work to be completed (Layer2) before proceeding further (Layer3) (we can block thread for now)
• When a new instance of class (Layer1) wants to start work and worj was already completed (on Layer2) then the result will be passed to following class Layer3 will use cached result (existing work result)
I imagine this is double with coroutines. Can anybody help me with writing this code?ephemient
10/13/2023, 12:34 AMPHondogo
10/13/2023, 5:35 AMephemient
10/13/2023, 6:22 AMPHondogo
10/13/2023, 8:28 AMigor.wojda
10/13/2023, 9:23 AMPHondogo
10/13/2023, 9:27 AMDavid Kubecka
10/14/2023, 4:00 AMjob.cancel() is there because atomocity of job vs result is not guaranteed. Is there any reason why not make it so, i.e. val result = pending.computeIfAbsent(key) { scope.async(...) }?
• Why there's also GlobalScope in the coroutine scope alongside Dispatchers.IO?ephemient
10/14/2023, 4:06 AM.computeIfAbsent may re-run the block multiple times when there are concurrent writersephemient
10/14/2023, 4:06 AMephemient
10/14/2023, 4:07 AMephemient
10/14/2023, 4:08 AMDavid Kubecka
10/14/2023, 4:11 AMbecauseI thoughtmay re-run the block multiple times when there are concurrent writers.computeIfAbsent
ConcurrentHashMap is there exactly to prevent concurrent block evaluations for the same key...ephemient
10/14/2023, 4:23 AM