chadmorrow
12/04/2018, 11:58 PMmp
12/05/2018, 12:03 AMpost('/foo') {
val response = async {
someHttpClient.doSomeRequest('<https://bar.com/quux>')
}.await()
if (response.statusCode == 200) {
call.respond(HttpStatus.Ok)
} else {
call.respond(HttpStatus.InternalError)
}
}
chadmorrow
12/05/2018, 12:46 AMval response
ends up returning unit and there's nothing i can call on itchadmorrow
12/05/2018, 12:46 AMchadmorrow
12/05/2018, 12:53 AMchadmorrow
12/05/2018, 12:53 AMdave08
12/05/2018, 1:32 AMgildor
12/05/2018, 1:52 AMasync{}.await()
already wrong itself, there are no cases when you need thismp
12/05/2018, 10:23 AMsuspend
, then you don’t need async
etc. If it returns CompletableFuture
or similar, then you would.mp
12/05/2018, 10:26 AMCompletionStage#asDeferred
IIRC. Or if it’s blocking, then more ceremony is required...)gildor
12/05/2018, 10:28 AMIf it returnsBut it will beor similar, then you would.CompletableFuture
CompletableFuture.await()
extension, not a Deffered.await()
mp
12/05/2018, 10:28 AMgildor
12/05/2018, 10:29 AMif it’s blocking, then more ceremony is requiredNot so much and also await() is not needed in this case
val result = withContext(IO) { someBlockingCall() }
mp
12/05/2018, 10:29 AMgildor
12/05/2018, 10:30 AMasync{}
, but in this case you never call it as async{}.await()
because it make impossible to run a few concrrent tasks
You would do rather something like:
val a = async{}
val b = async{}
a.await() + b.await()
mp
12/05/2018, 10:30 AM