Gov*_*ngh 9 java promise playframework java-8 playframework-2.3
void makePdfPage(String url, PdfContentByte contentByte){
com.itextpdf.text.Font sans = UtilityMethods.getSansSerifFont(14);
sans.setColor(80,147,225);
ColumnText ct = new ColumnText(contentByte);
ct.setSimpleColumn("Hello", 0, 780, 595, 830, 10, Element.ALIGN_CENTER);
try {
ct.go();
} catch (DocumentException e) {
System.out.println(e);
// TODO Auto-generated catch block
e.printStackTrace();
}
Promise<WSResponse> out = notification.call(url);
out.map(resp->{
Map<String,Object> mapp= Json.fromJson(resp.asJson().get("list"), Map.class);
PdfService.designPdf(mapp, contentByte);
return resp;
});
}
Run Code Online (Sandbox Code Playgroud)
contentByte 是空的 desginPdf
它是异步的,这就是为什么它没有contentByte的值,可以任何其他方式,所以我可以同步使用或任何其他方式来解决我的问题.
WSResponse resp = out.get(10000);
Run Code Online (Sandbox Code Playgroud)
失败了
我没有 Java Promise 的经验,但根据我在 Scala 的经验,我会尝试这样的事情:
Promise<WSResponse> out = notification.call(url);
WSResponse res = out.map(resp->{
Map<String,Object> mapp= Json.fromJson(resp.asJson().get("list"), Map.class);
PdfService.designPdf(mapp, contentByte);
return resp;
});
//Do something with res
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
357 次 |
| 最近记录: |