Service task being completed and process variable not being set before moving to next task

In my application I need to use a simple frontend(HTML) which interacts with the REST API that camunda provides, I use a nodejs library to create the job workers.(i’m using camunda-external-task-client-js l).
But Im facing a problem, the service task generates a value for X and I need the value X just after this to display on my frontend. In the frontend every process variable is returned except this. If i set a delay of 1 second/add a manual task in between then I am able to see the variable X . But is there any way that I can make the service task set the variable X and then get completed? I have tried using async before/after but it still did not work.