我正在寻找一种方法,将Vector[(Future[TypeA], TypeB)]
转换为输入代码Future[Vector[(TypeA, TypeB)]]
。
我意识到使用Future.sequence(...)
将一组期货转换为一个集合的未来,但是无法找到一种方法来管理从元组到未来到元组的未来的步骤
所以我正在寻找能够实现以下虚拟extractFutureFromTuple
所需功能的东西。
val vectorOfTuples: Vector[(Future[TypeA], TypeB)] = ...
val vectorOfFutures: Vector[Future[(TypeA, TypeB)]] = vectorOfTuples.map(_.extractFutureFromTuple)
val futureVector: Future[Vector[(TypeA, TypeB)]] = Future.sequence(vectorOfFutures)
答案 0 :(得分:2)
请注意,您只需拨打一次SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
InetSocketAddress address = new InetSocketAddress("10.1.2.3", 80);
Proxy proxy = new Proxy(Proxy.Type.HTTP,address);
factory.setProxy(proxy);
restTemplate.setRequestFactory(factory);
:
Future.traverse