irus
01/25/2019, 11:23 AMprivate val topics = mutableMapOf<String, Publisher>()
private val lock = Mutex()
suspend fun method(key: String) {
lock.withLock {
topics.getOrPut(key) { //... }
}
}
is lock gives guarantee that other coroutines will see changes in topics
?ghedeon
01/25/2019, 11:30 AMirus
01/25/2019, 11:40 AMghedeon
01/25/2019, 11:44 AMConcurrentHashMap
could be a better solution.irus
01/25/2019, 12:02 PM# thrift async server handler method:
override fun action(data, resultHandler: AsyncMethodCallback<ResultCode>) {
~ process(data)
resultHandler.onComplete(ResultCode.OK)
}
Where process
shown before
So I can create actor, and pass completion call:
{ resultHandler.onComplete(ResultCode.OK) }
as additional field in dataalso, if you have more reads than writes, instead of blocking the whole map,but it will block whole thread, that's I think can be badcould be a better solution.ConcurrentHashMap
ghedeon
01/25/2019, 12:08 PMDico
01/25/2019, 1:18 PMelizarov
01/25/2019, 1:26 PMghedeon
01/25/2019, 2:06 PMproduce
coroutine instead of CompletableDeferred<String?>
?Dico
01/25/2019, 2:10 PMCompletableDeferred
with a Continuation