Hi <@UE3D4UE15>, I saw in the channel history that...
# arrow
r
Hi @Bob Glamm, I saw in the channel history that you were working with ktor and you were trying to use IO as a ktor handler (which is suspended function). Have you managed to do that using Arrow 0.9.0 or you had to use snapshot version (0.10.0-SNAPSHOT)?
b
0.10.0-SNAPSHOT
Let me put up a gist of that on GitHub
Actually, check that, it works with 0.9.0
Bear in mind that it's really rough and fixed to
IO
r
Thanks! use of
suspendCoroutine
is a clue here, I'm checking is it possible to make this more abstract with
Async
typeclass still I cannot figure out is it possible or not
b
I am pretty sure it is possible to bound it to Async. One nice signature is
suspend MonadThrowSyntax<F>.(args) -> Kind<F, result>
which enables
fx
syntax within the adapted method block
Are you tied to 0.9.0 or can you migrate to 0.10.0-SNAPSHOT?
r
well, it's internal project, but some people will use, so I have some doubts should I switch to snapshot 😄
I can at least experiment and see what will hapend 😉
b
IIRC the
.suspended()
boilerplate is built into 0.10.0-SNAPSHOT, so it would make it a little simpler. Let me see if I can make it polymorphic on Async<F>
Updated with parts of it polymorphic on Async<F>
I think the routing {} block needs to be adapted to IO/F, though
hmm,
PipelineContext
and
Async<F>.later()
might be promising
This works as a starting point but is wrong:
Copy code
get("quux") {
                IO.async().effect(this.coroutineContext) {
                    call.respondText("QUUXER", ContentType.Text.Html)
                }.fix().suspended()
            }
I think the general structure we would want to expose is
suspend (PipelineContext<Unit, ApplicationCall>) -> Kind<F, A>
.. I think
The trick is that every call to
ApplicationCall
is a side-effect
The following is closer, I think:
Copy code
fun <F, TSubject: Any, TContext: Any> bridgeFactory(
        AF: Async<F>,
        PC: PipelineContext<TSubject, TContext>
): PipelineAsyncBridge<F, TSubject, TContext> =
        object: PipelineAsyncBridge<F, TSubject, TContext>, Async<F> by AF, PipelineContext<TSubject, TContext> by PC {}
then in `routing`:
Copy code
get("q2") { bridgeFactory(IO.async(), this).run {
                effect(this.coroutineContext) {
                    call.respondText("Q2", ContentType.Text.Html)
                }.fix().suspended()
            }}