Application context, request context and other scopes are empty in the futures. I've created futures with `loadAppContext=true` flag. For instance, `CGI` variables have blank values, `prc` is just empty. So it's hard to make a lot of different methods async.
For example, let's have a method that sends some emails in a loop, each email has a header with a site title that relies on `siteTitle` from the `prc`. If rewrite this loop to async using futures, like this:
.allApply(reviews, (review) => reviewService.deliverReview(review, event))
it will throw an error because `prc` or `event.getPrivateContext()` is empty inside a `deliverReview` in the future.
Could you please explain what am I doing wrong and maybe there is a solution for such usecase, or is it impossible to use application context in the futures? Thanks!
I am using a Lucee Server. Thanks for the explanation
Yep, that would be the issue. You may be able to pass a hard reference to the event object into your future. I’ll try to revisit this at some point, but basically, the methods Lucee uses to copy the details of a pagecontext into the thread’s pagecontext were not thread safe and would error out a lot under load. I reported this to the Lucee developers and spent hours trying to work around it, but I couldn’t find a solution that was error-free and the Lucee developers never got back to me. This is a deficiency in Lucee.
I see. Anyway, thank you for a great work on this. I hope one time Lucee will make pagecontext thread safe and we will be able to use a full power of Futures
Like Brad said we have limitations on the Lucee engine to provide us with all we need. However, you can still use hard references, but you will have to pass them into the future’s constructor or via closure references.
Thanks for an addition, I’ll try this approach