Rodrigo Silva
02/18/2020, 4:33 PMpakoito
02/18/2020, 4:35 PMpakoito
02/18/2020, 4:36 PMpakoito
02/18/2020, 4:36 PMBob Glamm
02/18/2020, 4:45 PMI've shipped a 20k LOC project in PHPPaco, you are a brave, brave man
Rodrigo Silva
02/18/2020, 5:00 PMpakoito
02/18/2020, 5:02 PMpakoito
02/18/2020, 5:09 PMRodrigo Silva
02/18/2020, 7:52 PMSatyam Agarwal
02/18/2020, 8:51 PMSatyam Agarwal
02/18/2020, 8:54 PMSatyam Agarwal
02/18/2020, 8:54 PMSatyam Agarwal
02/18/2020, 8:58 PMApplicationCall
instance, so I cannot make an extension function on IO to send response, and then it ends up looking like this :
IO.effect { myDomainResponse -> this.call.respond(myDomainResponse) }
which is not nice from purity point of view.Satyam Agarwal
02/18/2020, 8:58 PMpakoito
02/18/2020, 9:11 PMSatyam Agarwal
02/18/2020, 9:12 PMRodrigo Silva
02/18/2020, 10:03 PMSatyam Agarwal
02/18/2020, 10:24 PMRodrigo Silva
02/18/2020, 10:42 PMthan_
02/19/2020, 1:31 PMThe only problem is, respond(…) method which actually sends response in ktor, can only be called withinstance, so I cannot make an extension function on IO to send response, and then it ends up looking like this :ApplicationCall
IO.effect { myDomainResponse -> this.call.respond(myDomainResponse) }
which is not nice from purity point of view.I've had the same problem. This can be helped with few extension functions.
inline fun <reified T : Any> <http://Route.post|Route.post>(noinline body: suspend ConcurrentSyntax<ForIO>.(call: ApplicationCall, args: T) -> Unit): Route =
post<T>{
IO.fx {
body(call, it)
}.suspendCancellable()
}
fun ApplicationCall.respondEffect(status: HttpStatusCode, message: Any): IO<Unit> =
IO.effect { respond(status, message) }