Last active
July 19, 2018 05:36
-
-
Save mystdeim/859b062df5b0c3d2bd04097f530319a1 to your computer and use it in GitHub Desktop.
Coroutine example
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
class WebVerticle : CoroutineVerticle() { | |
suspend override fun start() { | |
val router = Router.router(vertx) | |
router.get("/api/account/:id").coroutine { account(it) } | |
// TODO | |
} | |
suspend internal fun account(ctx: RoutingContext) { | |
// TODO | |
} | |
fun Route.coroutine(coroutineHandler: suspend (RoutingContext) -> Unit): Route { | |
handler { | |
launch(vertx.dispatcher()) { | |
coroutineHandler.invoke(it) | |
} | |
} | |
return this | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment