Ryota
03/01/2019, 2:17 AMrunBlocking
usages and I’d love to get some pointer.
My goal is to start a blocking process with AWS Lambda, which would kick off a bunch of heavy tasks concurrently, and then returns the aggregate of the tasks when they are all completed (or when any canceled).
Because the Lamdba interface itself is not a suspending function (i.e. RequestHandler<I, O>
interface needs function with signature of public O handleRequest(I input, Context context)
), I will need a coroutine builder inside handleRequest
method to await for the tasks. I have read in a few places how runBlocking
is only meant to be used for unit testing mainly, and should not be used in production. What I want to achieve seems to require runBlocking
for good reason, but I am unsure if I’m missing something obvious.
Given serverless function requiring a blocking call, is runBlocking
a legitimate approach in this scenario? Or is there something that I’m missing? Thanks in advance for your support!Ryota
03/01/2019, 9:19 AMrunBlocking
is a bridge between blocking and async, but should not be abused - and what that “abuse” really meant. It would be really nice if the Lambda can fully understand the promise-like abstraction, or even just provide suspending function interface for Kotlin. But in its own implementation, I assume they would likely need to do some blocking like runBlocking
. It makes sense how runBlocking
in this scenario is the only way to achieve my goal.groostav
03/03/2019, 8:27 PMIt would be really nice if the Lambda can fully understand the promise-like abstraction, or even just provide suspending function interface for KotlinBe careful what you wish for. GRPC does this by using callbacks everywhere and it confuses me on a regular basis. Its not too hard to write an adapter (assuming a simple thread-pooling strategy works for you), but then you end up using that adapter liberally.
Ryota
03/04/2019, 12:35 AMrunBlocking
to wrap the suspending functions, doesn’t it? And that’s how you may end up using it ubiquitously?