<https://github.com/JakeWharton/SdkSearch/blob/mas...
# coroutines
u
https://github.com/JakeWharton/SdkSearch/blob/master/sync/src/commonMain/kotlin/com/jakewharton/sdksearch/sync/ItemSynchronizer.kt
Copy code
private val _state = ConflatedBroadcastChannel<SyncStatus>()
   val state: ReceiveChannel<SyncStatus> get() = _state.openSubscription()

  fun forceSync() {
    _state.offer(SyncStatus.SYNC)
    GlobalScope.launch {
      val result = if (load()) SyncStatus.IDLE else SyncStatus.FAILED
      _state.offer(result)
    }
  }
how would you handle this if forceSync() took an parameter? Channel per params would be needed @gildor
g
But what exactly it should sync?
In this example it just reads current status again
u
Im imagining how to expand this, if forceSync took parameter, which would narrow down the sync operation for example
which means you could have mutiple syncs (per param )going on at the same time, which implies channel per running sync
g
if it’s kinda continue of discussiion with
postMessageOBservable
, than this forceSync with param just would clear cached value
But again, semantics of your code is different, you just post value and do not await other values
u
..would clear cached value? I dont follow
g
if you need stream of events (like in this case), you need some different way
again, I’m just guessing what you want to achive
u
channel is a stream of events, isnt it?
g
semantics of this class from SdkSearch is pretty clear for me
yes, channeels is a stream of events
u
im trying to achieve
forceSync(target: Target) {}
instead of
forceSync()
where Target is for example Foo, Bar tables, whatever
so sync of Foo and sync of Bar can run in parallel, and you need states of both in various parts of ui
tldr; you cannot have single channel for this, I think
g
Could you show full example of such class
u
I dont have an example, im just imagining this Jake's class how would one extend it, since now forceSync presumably only syncs everything, therefore no param is needed and single _state Channel is sufficient
g
this class exposes one channel of events
u
yes, which would not do if we were to parametrize the forceSync function
g
if you need abstraction that exposes different channel depending on Target it will be very different, so forceSync is not your only problem in this case
u
yes, possibly
g
definitely
u
so..how? map of channels?
g
I don’t know, depending on your case and semantics which you want to have
there is no universal solution
u
well Id like semantincs like in the sample but be able to add params to forceSync
g
If we talking about this example, you can build some manager of ItemSynchronizer that create new ItemSynchronizer for each Target
u
true, buts thats just moving the map from synchronizer to manager, right?
i.e. map of channels becomes map of itemsynchronizers
g
well Id like semantincs like in the sample but be able to add params to forceSync
It’s not the only thing what you need, I believe you also need some sort of parameterized
state
which require completely different implementation
u
yea I thought about parametrizing State like State(target) and then filter in the callsite
but, that would have issue of replays,i.e it would only cache last, regardless of target, you'd need cache per target, to not miss stuff
in which case you might awswell have map of channels per target
this all COULD work if Target is exhaustive, like enum
but what if there are more variable params like Int or whatever
@jw maybe?