Skip to content

Instantly share code, notes, and snippets.

@Jian-Min-Huang
Last active May 22, 2021 05:19
Show Gist options
  • Save Jian-Min-Huang/a4b63af9b9544c5bd2fec8ed104980c5 to your computer and use it in GitHub Desktop.
Save Jian-Min-Huang/a4b63af9b9544c5bd2fec8ed104980c5 to your computer and use it in GitHub Desktop.
fun blockingMvc() =
run {
// action 1, cost 100ms
val delay100res = getBlockingResponse(100)!!["totalTimeMillis"].parseLong()
// action 2, cost 200ms
val delay200res = getBlockingResponse(200)!!["totalTimeMillis"].parseLong()
// action 3, need return value from action 1 and 2, cost 300ms
val delay300req = getBlockingResponse(delay100res + delay200res)!!["totalTimeMillis"].parseLong()
// action 4, cost 400ms
val delay400req = getBlockingResponse(delay300req + 100)!!["totalTimeMillis"].parseLong()
// action 5, cost 500ms
val delay500req = getBlockingResponse(delay300req + 200)!!["totalTimeMillis"].parseLong()
mapOf(
"delay100req" to delay100res,
"delay200req" to delay200res,
"delay300req" to delay300req,
"delay400req" to delay400req,
"delay500req" to delay500req
)
}
private fun getBlockingResponse(ms: Long) = webClient.get()
.uri("http://$domain:8888/delay/ms/$ms")
.retrieve()
.bodyToMono(object : ParameterizedTypeReference<Map<*, *>>() {})
.block()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment