Rest api to process engine to start a start and retrieve result as response

I like to create a rest api where I can create a task and wait until task is complete and return camunda variable as response at the end.
Basically trying to convert existing api and business workflow written in java to camunda but keeping the api as synchronous.
So far what I found is, I can start a task and then consumer has to keep making a call to check of task is complete or not.

Camunda process engine is started with spring boot.

Check this thread Camunda StartProcess/withResult

I figured it out. Camunda Server gets the control back as soon as very first wait state occurred.
Note: If you have external task or user tasks, then process wont be complete but server will get the control and following code will return process variables.
For anyone who is interested in java codeā€¦

    @RequestMapping(value = "/execute", method = RequestMethod.GET, produces = {"application/json"})
    @ResponseStatus(HttpStatus.OK)
    public @ResponseBody VariableMap execute() {


        ProcessInstanceWithVariables instance1 = runtimeService.createProcessInstanceByKey("spring-boot-example-process")
                .setVariable("creditor", "Nice Pizza Inc.")
                .setVariableLocal("destination", "12 High Street")
                .executeWithVariablesInReturn();

        VariableMap variableMaps = instance1.getVariables();

        return  variableMaps;

    }