Last active
June 2, 2021 08:36
-
-
Save Jian-Min-Huang/87e2b7c0b1efff59884bd87fa5cceed8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun async() = | |
| arrayOf(getFutureResponse(100), getFutureResponse(200)) | |
| .let { | |
| allOf(*it) | |
| .thenApply { v -> | |
| return@thenApply it.map { v1 -> v1.get() }.toMutableList() | |
| }.thenApply { v -> | |
| val delay300res = getFutureResponse(v[0]["totalTimeMillis"].parseLong() + v[1]["totalTimeMillis"].parseLong()) | |
| delay300res.join() | |
| v.add(delay300res.get()) | |
| return@thenApply v | |
| }.thenApply { v -> | |
| val delay400res = getFutureResponse(v[2]["totalTimeMillis"].parseLong() + 100) | |
| val delay500res = getFutureResponse(v[2]["totalTimeMillis"].parseLong() + 200) | |
| allOf(delay400res, delay500res) | |
| .thenApply { | |
| v.add(delay400res.get()) | |
| v.add(delay500res.get()) | |
| return@thenApply v | |
| } | |
| }.thenApply { v -> | |
| mapOf( | |
| "delay100res" to v.get()[0]["totalTimeMillis"], | |
| "delay200res" to v.get()[1]["totalTimeMillis"], | |
| "delay300res" to v.get()[2]["totalTimeMillis"], | |
| "delay400res" to v.get()[3]["totalTimeMillis"], | |
| "delay500res" to v.get()[4]["totalTimeMillis"] | |
| ) | |
| } | |
| } | |
| private fun getFutureResponse(ms: Long) = webClient.get() | |
| .uri("http://$domain:8888/delay/ms/$ms") | |
| .retrieve() | |
| .bodyToMono(object : ParameterizedTypeReference<Map<*, *>>() {}) | |
| .toFuture() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment