2017-09-27 33 views
0

如何在ratpack中使用blocking.get方法後返回一個對象或列表。在Ratpack的Blocking.get中返回一個值

Blocking.get(()-> 
      xRepository.findAvailable()).then(x->x.stream().findFirst().get()); 

上面的代碼返回void - 我希望能夠做到像下面這樣的東西,以便它返回then子句中的對象。我試着添加一個return語句,但不起作用。

Object x = Blocking.get(()-> 
       xRepository.findAvailable()).then(x->x.stream().findFirst().get()); 

回答

0

您可以使用地圖來處理可用的值。

Blocking.get(()-> 
      xRepository.findAvailable()).map(x->x.stream().findFirst().get()).then(firstAvailable-> ctx.render("Here is the first available x " + firstAvailable)) 
+0

如何返回在then子句中檢索到的對象 - 我不想做ctx.render – somename