Skip to content

Instantly share code, notes, and snippets.

@mystdeim
Last active July 19, 2018 05:36
Show Gist options
  • Save mystdeim/859b062df5b0c3d2bd04097f530319a1 to your computer and use it in GitHub Desktop.
Save mystdeim/859b062df5b0c3d2bd04097f530319a1 to your computer and use it in GitHub Desktop.
Coroutine example
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