https://kotlinlang.org logo
#coroutines
Title
# coroutines
a

Adam Powell

07/28/2019, 7:12 PM
anything you use for a return path there will involve some overhead, but you can read the source for Channel, they're fairly small/don't involve a lot of initialization overhead. You might find
CompletableDeferred
to be a better option for just a single value though
c

CLOVIS

07/28/2019, 7:21 PM
How would I use it? Based on the little example I wrote (or something completely different)
a

Adam Powell

07/28/2019, 7:29 PM
probably something like
Copy code
class Request<I, R>(val id: I) {
  val result: CompletableDeferred<R>()
}
val ch = Channel<Request<I, R>>()
with a send-request looking something like
Copy code
val req = Request(id)
ch.send(req)
val result = req.result.await()
and then the receiver does
req.result.complete(fetchedValue)
then all of the details managing the difference between requesting scope and cache-owner scope, cancellation of either
c

CLOVIS

07/28/2019, 7:37 PM
Thanks a lot, I'll look into that ^^
5 Views