DeferredResult не возвращает ожидаемый ответ - PullRequest
0 голосов
/ 26 апреля 2019

Я использую @RestController с методом, который возвращает DeferredResult.

У меня есть список завершаемого будущего, каждый с различными этапами, как указано ниже

for (Integer unit : getIds()) {
    futureList.add(CompletableFuture.completedFuture(unit)
        .thenApply(id -> CompletableFuture
            .completedFuture(service.get1(id))
            .thenCombineAsync(CompletableFuture.completedFuture(b), (a, df1) -> 
                CompletableFuture.completedFuture(service.validate(Optional.ofNullable(a),c, 
                        b, dealerCode))
                .thenApplyAsync(status -> CompletableFuture.completedFuture(b))
                .thenCombineAsync(CompletableFuture.completedFuture(a), (b1, a1) -> 
                    service.mapToTrans(Optional.ofNullable(a), b, c))
                .handle((response, exception) -> {
                    if(exception == null) {
                        return response;
                    }
                    else {
                        handler.handleException(exception, results);
                        return null;
                    }
                })
                .thenApplyAsync(t -> service.submitRequest(Optional.ofNullable(a), c))
                .thenApplyAsync((t) -> service.saveTransaction(Optional.ofNullable(t)))
                .thenAccept(result1 -> results.add(result1))
            )
            .handle((response, exception) -> handleStage(response, exception, results))
        )
        .handle((response, exception) -> handleStage(response, exception, results))
        );
}

Я устанавливаю результат в DeferredResult, как указано ниже

futureList.forEach(cf -> { 
            CompletableFuture.allOf(cf).join();
        });
        deferredResult.setResult(ResponseEntity.ok().body(results));
    })

Номой ответ состоит в том, что в массиве "result" содержится только меньше элементов.Из журналов видно, что все фьючерсы успешно выполняются.Пожалуйста, дайте мне знать, в чем проблема

...