Skip to content

Instantly share code, notes, and snippets.

@phiSgr
Created December 23, 2017 02:53
Show Gist options
  • Save phiSgr/e75e28410f516eb0d3c092bd3da73c94 to your computer and use it in GitHub Desktop.
Save phiSgr/e75e28410f516eb0d3c092bd3da73c94 to your computer and use it in GitHub Desktop.
Vert.x Future with sync and async callbacks and coroutines
val future1 = Future.future<Unit>()
launch (context = vertx.dispatcher()) {
future1.await()
// Code in coroutine running in vert.x-eventloop-thread-0
println("Code in coroutine running in ${Thread.currentThread().name}")
}
val future2 = Future.future<Unit>()
future2.setHandler {
// Code in handler running in thread-of-another-component
println("Code in handler running in ${Thread.currentThread().name}")
}
thread(name = "thread-of-another-component") {
future1.complete(Unit)
future2.complete(Unit)
}
Thread.sleep(100)
future2.setHandler {
// Code in determined future handler running in main
println("Code in determined future handler running in ${Thread.currentThread().name}")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment