com.huanshankeji.vertx.Web.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-common-vertx Show documentation
Show all versions of kotlin-common-vertx Show documentation
Huanshankeji's common code libraries in Kotlin
package com.huanshankeji.vertx
import io.netty.handler.codec.http.HttpResponseStatus.FORBIDDEN
import io.netty.handler.codec.http.HttpResponseStatus.UNAUTHORIZED
import io.vertx.ext.web.RoutingContext
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.launch
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
fun RoutingContext.failWithUnauthorized() =
fail(UNAUTHORIZED.code())
fun RoutingContext.failWithForbidden() =
fail(FORBIDDEN.code())
inline fun RoutingContext.checkedRun(block: () -> Unit): Unit =
try {
block()
} catch (t: Throwable) {
fail(t)
}
inline fun CoroutineScope.launchChecked(
ctx: RoutingContext,
context: CoroutineContext = EmptyCoroutineContext,
start: CoroutineStart = CoroutineStart.DEFAULT,
crossinline block: suspend CoroutineScope.() -> Unit
) =
launch(context, start) {
ctx.checkedRun { block() }
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy