Coroutines and Weld RequestScope


#1

Hi all, i’m working with kotlin coroutines and vert.x and it’s amazing, so simple, fast and lightweight.
And as a Java developer, coming from JEE, i want to use CDI (Weld).
In simple things it works fine, but when i try to propagate @RequestScope in coroutine call the problems begin.

Weld is developed do work with ThreadLocal storage for scope, and propagate that scope in a Stack, coroutines are more complex than it, and the request scope not work correctly, in simple method call with coroutines the request scope is not propagated.

So I want help about how correct propagate that scope, in my research i see suggestions to work with custom CoroutineScope or Create a custom CDI Scope.


#2

i’m not very familiar with cdi, but if you really want to use it, maybe you need to use a custom scope bound to a property of coroutineContext (which is this “equivalent” of threadlocal for coroutines).

Still my advice would be kiss (which I don’t consider JEE to be).


#3

thanks for the reply, i’ll read about it

About CDI, it’s really simple, and my base architecture (i’m migrating a legacy system in JEE) is totally based on CDI

about the coroutine context, it is possible to propagate threadlocal values in it?


#4

if you can access the threadlocal you can read it & then put its value in the coroutine context. Then using a continuationInterceptor you can restore it in the threadlocal. that looks ugly… but it could work.