ktor icon indicating copy to clipboard operation
ktor copied to clipboard

Cannot use suspending functions in call.respondHtml

Open wdoeland opened this issue 7 years ago • 3 comments

Running a suspending function in call.respondHtml will stop everything from there from rendering and being sent to the client.

https://kotlinlang.slack.com/archives/C0A974TJ9/p1496430950490462

wdoeland avatar Jun 03 '17 07:06 wdoeland

So given a little bit more thought to this, it's not possible right now. Even if respondHtml would accept a suspending lambda, which it can, all the builder functions for tags from kotlinx.html are non-suspending. Can you provide a little bit more context what is a suspending function you want to call inside html building?

orangy avatar Jun 05 '17 15:06 orangy

@orangy btw, I believe html building functions could be made inline so suspensions will work well except that writing to the output channel will be blocking (tag consumer could be suspend as well but it will have performance impact). However making functions inline leads to bytecode size growth so I am not completely sure whether it is a good idea or not.

cy6erGn0m avatar Jun 15 '17 20:06 cy6erGn0m

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

oleg-larshin avatar Aug 10 '20 15:08 oleg-larshin