Hi, afaik one only needs to use Environment() for ...
# arrow
o
Hi, afaik one only needs to use Environment() for unlocking Arrow FX Coroutines, if there's no suspended entry point in the environment. Ktor and Spring Boot are supposed to have such, but I don't find any suspended router functions. Do I have to rely on the fancy banner saying "Co-Routines included!" to decide, if I need to use Environment() or not, or am I missing something? 🤔
s
Hey Oliver,
Environment
doesn’t exist anymore, and you can simply use
runBlocking
from KotlinX if you need to. But Ktor is full of
suspend
APIs, especially in
routing
, so I think you’re not looking in the right place.
Spring it depends which dependencies you have on the classpath, but if I am working on a Spring project that doesn’t support
suspend
I typically use
CompletableFuture
. https://github.com/joost-de-vries/spring-coroutine https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-jdk8/index.html With these two dependencies you can safely launch coroutines as CompletableFuture without breaking cancellation.
It’s the next best thing in Spring MVC style, if you’re using Spring WebFlux then you can depend on the
suspend
APIs that are built on top of Project Reactor such as
coRouter
which has a
suspend
DSL inside.
o
Hi Simon,
Environment
is gone? Guess my course material is outdated. 😀 I think, I did not make myself really clear, so please let my correct my intention: I did not find suspended endpoints in the Ktor docs. And while I did find some suspended functions in their github after you answered, I still feel unshure about how to use it with Arrow Fx - it's not like 'coRouter' that imho clearly states "here be coroutines". So I'm really looking forward to the KTOR backend project you mentioned in the other thread! 🦜 Suspended endpoints in Spring...man, they always get me so confused. I forget about WebFlux / Reactor and have to look up for the n-th time, if there's support for suspend endpoitns in MVC. Did so (again) and found that there would be no need for runBlocking { ... } for Spring Framework 5.3 and Spring Boot 2.4 (meaning you can just use suspend as in webflux). But I guess I will have forgotten that again after hitting enter. 😬 Thank you very much for the detailed answer and the links! 🙏
s
I have never been able to make suspend fun work without WebFlux on the classpath, but I’m liking Ktor more if I can use it
I’m trying to clean it up, but release 1.0.0-M1 is getting a bit in between but you can expect both in August
🙌 1
At least a V1 of the back-end, I’ll continue working on it in the future
o
Thanks again! 👍
Hi @simon.vergauwen, I made Arrow Fx work with the classic web-starter, want to have a look? 🙂
I couldn't use Web.fn and the
router {}
dsl, though. But the annotation based controller functions can be suspended:
@GetMapping(value = ["/parZip"])       suspend fun parZip(): ResponseEntity<String> {
s
Oh nice, thanks for sharing!
🙏 1
o
Didn't notice you replied. Sorry! 😅