Created
December 23, 2017 02:53
-
-
Save phiSgr/e75e28410f516eb0d3c092bd3da73c94 to your computer and use it in GitHub Desktop.
Vert.x Future with sync and async callbacks and coroutines
This file contains 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
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