如何使用Java中的Twitter Future
,如何在Future
链中使用一个创建的map
中的上下文?
我已经使用Contexts.local()
尝试了以下操作:
LocalContext.Key<String> key = Contexts.local().newKey();
Contexts.local().let(key, "SomeValue", func(() -> {
System.out.println("inside let binding " + Contexts.local().get(key));
return FuturePools.unboundedPool().apply(() -> {
System.out.println("inside let binding but in other thread " + Contexts.local().get(key));
return "initial future";
});
})).map(v -> {
// How to get the context here? The line below prints None
System.out.println("outside let binding " + Contexts.local().get(key));
return "mapped future";
});
不幸的是,在粘贴到map
的lambda中,设置值不再可用。我也要怎么做才能在那里提供它?以及如何在Java中做到这一点?
例如Twitter Promise
的{{1}}实现实现了map
,但我看不到向Local.save()
添加值的方法。