如何在Java中的Twitter Future中传递上下文

时间:2018-12-14 10:06:23

标签: java twitter future continuations

如何使用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()添加值的方法。

0 个答案:

没有答案