create CompletableFuture

Manually created future:
val future = CompletableFuture<String>()
// Completing it programmatically
future.complete("Result-Val")

println("Some other work")

println(future.get()) 

Output:

Some other work
Result-Val
GT-snapshot

Command to reproduce:

gt.sandbox.checkout.commit b581f798c55d205c6e91 \
&& cd "${GT_SANDBOX_REPO}" \
&& cmd.run.announce "./gradlew run"

Recorded output of command:

> Task :app:checkKotlinGradlePluginConfigurationErrors SKIPPED
> Task :app:processResources NO-SOURCE
> Task :app:compileKotlin
> Task :app:compileJava NO-SOURCE
> Task :app:classes UP-TO-DATE

> Task :app:run
Some other work
Result-Val

BUILD SUCCESSFUL in 874ms
2 actionable tasks: 2 executed
Asynchronous task:
val future = CompletableFuture.supplyAsync {
  out.println("Starting to sleep")
  Thread.sleep(1000)
  out.println("Finished sleeping")
  "Hello, CompletableFuture!"
}

out.println("Hello, from Main thread")
out.println(future.get()) // Output: Hello, CompletableFuture!
GT-Snapshot

Command to reproduce:

gt.sandbox.checkout.commit 9dd9ad6c4750da8e7b93 \
&& cd "${GT_SANDBOX_REPO}" \
&& cmd.run.announce "./gradlew run"

Recorded output of command:


[2024-11-22T04:33:14.166261Z][elapsed-since-start:   42ms][tname:ForkJoinPool.commonPool-worker-1/tid:20] Starting to sleep
[2024-11-22T04:33:14.166259Z][elapsed-since-start:   42ms][tname:main/tid:1] Hello, from Main thread
[2024-11-22T04:33:15.193044Z][elapsed-since-start: 1058ms][tname:ForkJoinPool.commonPool-worker-1/tid:20] Finished sleeping
[2024-11-22T04:33:15.194765Z][elapsed-since-start: 1059ms][tname:main/tid:1] Hello, CompletableFuture!

Backlinks