减少期货清单 [英] Reducing a list of futures

查看:67
本文介绍了减少期货清单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有个运行时间长的函数,返回的未来如下:

I have long running function that returns a future as follows:

def longRunningFunction(signs: List[String], numOfWords: Int)
    : Future[List[(String, Int)]] = Future{ /* computation */ }

我需要按以下方式减少Future的输出:

I need to reduce the output of the Future as follows:

val all = (6 to 24).map(i => longRunningFunction(signs, i))
                   .reduce(_ ::: _)

但这似乎不起作用。有什么想法吗?

But this does not seem to work. Any thoughts?

推荐答案

Future.reduce(futures)(_ ::: _)

文档

这篇关于减少期货清单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆