micronaut-projects / micronaut-aws

Projects specific to integrating Micronaut and Amazon Web Services (AWS)
Apache License 2.0
87 stars 80 forks source link

Support Kotlin coroutine out of the box in function apps #1079

Open dynaxis opened 3 years ago

dynaxis commented 3 years ago

Different from the plain Micronaut apps, function apps running on the AWS Lambda don't recognize suspend functions in controllers. It would be good if suspend functions are recognized out of the box in the same way as the plain Micronaut apps.

I at least hope to know if it's not and won't be implemented for any good reason. If that's not the case, I might step in to implement it and contribute back.

Thanks in advance.

sdelamo commented 3 years ago

https://twitter.com/dynaxis/status/1398923811303477253?s=20

@dynaxis

I wrote a AWS Lambda app in Kotlin w/ Micronaut, and became to know it doesn't support Kotlin coroutine out of the box after a few hours of struggling. Couldn't find any doc mentioning how Lambda is different from plain Micronaut apps.

@graemerocher

Not sure how coroutines help in a lambda context since they are inherently single threaded. Maybe you can elaborate a use case

@dynaxis

Then` reactive types should not be supported either. It's more or less about the consistency across different runtimes, IMHO.

Also coroutine helps even w/ single underlying thread, esp. if you are doing a lot of async things inside like sending out multiple requests at the same time.

@dynaxis

I'm currently making a lot of requests to various AWS services at the same time w/ coroutines.

@graemerocher

Sure I understand that use case but then you may as well await and send a synchronous response back as the return type of the lambda

The consistency comment I agree with however. You should get involved, great thing about OSS is that contributions are welcome!

@dynaxis

Yes, wrapping every handler in runBlocking should solve the problem. Or as I did this time, Rx builder provided by JetBrains will do too. At least, relevant Micronaut docs should mention lambda is different in that regard.