Replies: 2 comments 7 replies
-
This should work.
I'm not 100% sure but I don't think this would work because You might need something like An alternative might be to inject the CC @cescoffier
It depends on the scope of the injected bean. For example, it's always safe to use |
Beta Was this translation helpful? Give feedback.
-
Hi! Try using something like this pattern: @Path("test")
Uni<Integer> testExample() {
sideJob(n).runSubscriptionOn(Infrastructure.getDefaultWorkerPool())
.subscribeAsCompletionStage()
.whenComplete((i, e) -> {
if(e != null) {
logger.error(e.getLocalizedMessage());
}
});
return mainJob();
} Uni<Void> sideJob(int n) {
return Uni.createFrom().voidItem()
.onItem().delayIt().by(Duration.ofSeconds(2)) // simulate delay for 2 second
.map(v -> {
logger.log("result " + n);
return v;
});
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
quarkus reactive uses mutiny to handle task asynchronously.
But, a normal flow is always wait every jobs to finish, then returns the result.
Sometime, I just want to trigger a job and let it run in the background without waiting it to be done.
Any suggestion or example?
There are two ideas from my understanding,
What is the suggested solution for this use case in Quarkus?
Or, with the subscribe() way, does the context work?
e.g. sideJob() may use injected objects, when mainJob result is returned to client, are those objects still available to sideJob() (it should still run after the response has been sent to client and may last several minutes)?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions