ring

wombawomba 2021-11-02T12:02:16.003400Z

I'm rewriting an app with synchronous handlers to be async, and I don't want to have to rewrite all my endpoint handlers to be async. Is there an async->sync middleware somewhere that I can put at the top of my middleware stack to handle this?

emccue 2021-11-05T23:14:24.008600Z

@wombawomba maybe a silly question - but why are you rewriting your app to be async

Ben Sless 2021-11-04T05:11:36.006600Z

It's a bit difficult to know which happen before and which happen after the handler without some analysis. If you do know then you can write a "translator"

wombawomba 2021-11-15T14:36:25.009800Z

oh whoops, missed this

wombawomba 2021-11-15T14:36:41.010Z

I went ahead and wrote an async->sync middleware, which worked

wombawomba 2021-11-15T14:37:02.010300Z

anyway, the idea is to eventually get rid of it and make everything async

wombawomba 2021-11-15T14:38:34.010500Z

the main point in making things async would be to prevent requests from hogging threads

emccue 2021-11-06T19:01:42.008800Z

And then the follow up is - the model that lets you work with async code the same as sync code is the interceptor model

emccue 2021-11-06T19:02:30.009Z

Pedestal does this, there might be some library that implements it separately, but that is the way

emccue 2021-11-06T19:04:19.009200Z

The other is to try a loom EAP and then see if that does enough for you

emccue 2021-11-06T19:05:10.009400Z

Then hope/cope

emccue 2021-11-06T19:06:12.009600Z

Because making an async->sync middleware would probably negate whatever benefit you hoped to get from being async otherwise

emccue 2021-11-16T14:20:57.010700Z

@wombawomba https://openjdk.java.net/jeps/8277131

wombawomba 2021-11-16T14:21:51.011Z

oh, cool

wombawomba 2021-11-16T14:22:48.011200Z

not sure when that feature will land though?

wombawomba 2021-11-16T14:23:00.011400Z

also, it seems like I'd have to wait for my webserver (Jetty) to support it

emccue 2021-11-16T14:23:24.011600Z

It will preview in 18 or 19. Thats March or September.

emccue 2021-11-16T14:23:31.011800Z

> A preview feature is a new feature whose design, specification, and implementation are complete, but which is not permanent, which means that the feature may exist in a different form or not at all in future JDK release

emccue 2021-11-16T14:24:36.012Z

and you can already use it with jetty

wombawomba 2021-11-16T17:57:49.012600Z

oh, neat