55 */
66package io.jooby
77
8- import io.jooby.Router.*
9- import kotlinx.coroutines.*
8+ import io.jooby.Router.DELETE
9+ import io.jooby.Router.GET
10+ import io.jooby.Router.HEAD
11+ import io.jooby.Router.OPTIONS
12+ import io.jooby.Router.PATCH
13+ import io.jooby.Router.POST
14+ import io.jooby.Router.PUT
15+ import io.jooby.Router.TRACE
16+ import kotlinx.coroutines.CoroutineExceptionHandler
17+ import kotlinx.coroutines.CoroutineScope
18+ import kotlinx.coroutines.CoroutineStart
19+ import kotlinx.coroutines.asCoroutineDispatcher
20+ import kotlinx.coroutines.launch
1021import kotlin.coroutines.CoroutineContext
1122
1223internal class RouterCoroutineScope (override val coroutineContext : CoroutineContext ) : CoroutineScope
@@ -24,45 +35,45 @@ class CoroutineRouter(val coroutineStart: CoroutineStart, val router: Router) {
2435
2536 @RouterDsl
2637 fun get (pattern : String , handler : suspend HandlerContext .() -> Any ) =
27- route(GET , pattern, handler)
38+ route(GET , pattern, handler)
2839
2940 @RouterDsl
3041 fun post (pattern : String , handler : suspend HandlerContext .() -> Any ) =
31- route(POST , pattern, handler)
42+ route(POST , pattern, handler)
3243
3344 @RouterDsl
3445 fun put (pattern : String , handler : suspend HandlerContext .() -> Any ) =
35- route(PUT , pattern, handler)
46+ route(PUT , pattern, handler)
3647
3748 @RouterDsl
3849 fun delete (pattern : String , handler : suspend HandlerContext .() -> Any ) =
39- route(DELETE , pattern, handler)
50+ route(DELETE , pattern, handler)
4051
4152 @RouterDsl
4253 fun patch (pattern : String , handler : suspend HandlerContext .() -> Any ) =
43- route(PATCH , pattern, handler)
54+ route(PATCH , pattern, handler)
4455
4556 @RouterDsl
4657 fun head (pattern : String , handler : suspend HandlerContext .() -> Any ) =
47- route(HEAD , pattern, handler)
58+ route(HEAD , pattern, handler)
4859
4960 @RouterDsl
5061 fun trace (pattern : String , handler : suspend HandlerContext .() -> Any ) =
51- route(TRACE , pattern, handler)
62+ route(TRACE , pattern, handler)
5263
5364 @RouterDsl
5465 fun options (pattern : String , handler : suspend HandlerContext .() -> Any ) =
55- route(OPTIONS , pattern, handler)
66+ route(OPTIONS , pattern, handler)
5667
5768 fun route (method : String , pattern : String , handler : suspend HandlerContext .() -> Any ): Route =
58- router.route(method, pattern) { ctx ->
59- launch(ctx) {
60- val result = handler(HandlerContext (ctx))
61- if (result != ctx) {
62- ctx.render(result)
69+ router.route(method, pattern) { ctx ->
70+ launch(ctx) {
71+ val result = handler(HandlerContext (ctx))
72+ if (result != ctx) {
73+ ctx.render(result)
74+ }
6375 }
64- }
65- }.setHandle(handler).attribute(" coroutine" , true )
76+ }.setHandle(handler).attribute(" coroutine" , true )
6677
6778 internal fun launch (ctx : Context , block : suspend CoroutineScope .() -> Unit ) {
6879 val exceptionHandler = CoroutineExceptionHandler { _, x -> ctx.sendError(x) }
0 commit comments