https://kotlinlang.org logo
Title
f

Francis Reynders

03/07/2023, 4:08 PM
Hi, I try to apply the new Raise functionality to some new code. Does this look like a correct way to use it? Trying to instantiate HttpClient and WsHttpClient in a safe way using either, catch and Raise DSL. Any feedback is appreciated.
s

simon.vergauwen

03/07/2023, 4:14 PM
Which
HttpClient
are you using? Typically you need to call some finalisers after you're done working with them. I often use
ResourceScope
for this. You can still combine it with
Either
as well. Here I am doing so for a
Postgres
driver. https://github.com/nomisRev/ktor-k8s-zero-downtime/blob/33739b6cb4db1661aa3c8f7b72[…]994/src/commonMain/kotlin/com/fortysevendegrees/env/postgres.kt Here I consume the code combining
either
with
resourceScope
. https://github.com/nomisRev/ktor-k8s-zero-downtime/blob/33739b6cb4db1661aa3c8f7b7293de5c80246994/src/commonMain/kotlin/com/fortysevendegrees/main.kt#L22
f

Francis Reynders

03/07/2023, 4:23 PM
Thanks for the quick feedback. I'm using Jetty. Yes I had
ResourceScope
and
SuspendApp
in mind as well, I thought to apply that later but I may need to already think about how to structure that in a dependent way. Your examples look very nice, will try to base it on that.
s

simon.vergauwen

03/07/2023, 4:25 PM
My pleasure. Be sure to ask any question if you encounter anything weird, or have any doubts.