https://kotlinlang.org logo
Title
p

Pavel Kunyavskiy [JB]

03/14/2023, 4:20 PM
Hi. What is a good way to answer http get query with stream of events. I mean, no content length, infinity long living query, which sometime print a line to output, if client is still there. call.respondOutputStream with explicit flushes seams to be working, but doesn't look suspend friendly. Won't it block more threads than needed?
a

Aleksei Tirman [JB]

03/14/2023, 5:01 PM
You can try using the
call.respondBytesWriter {}
that uses a
ByteWriteChannel
under the hood.
p

Pavel Kunyavskiy [JB]

03/14/2023, 5:07 PM
But it still looks like blocking API, as lambda itself wouldn't be suspend.
a

Aleksei Tirman [JB]

03/14/2023, 5:10 PM
The lambda is suspendable. What do you mean that it wouldn’t be suspend?
p

Pavel Kunyavskiy [JB]

03/14/2023, 5:14 PM
Hm. I need to recheck API. But anyway, writer.flush() is not suspend.