【发布时间】:2015-02-19 21:32:43
【问题描述】:
我正在阅读此博客 post,声称 Futures 不是“功能性的”,因为它们只是 副作用 计算的包装。例如,它们包含 RPC 调用、HTTP 请求等。是否正确?
博文给出了以下示例:
def twoUsersFeed(a: UserHandle, b: UserHandle)
(implicit ec: ExecutionContext): Future[Html] =
for {
feedA <- usersFeed(a)
feedB <- usersFeed(b)
} yield feedA ++ feedB
you lose the desired property: consistent results (the referential transparency). Also you lose the property of making as few requests as possible. It is difficult to use multi-valued requests and have composable code.
恐怕我不明白。您能解释一下在这种情况下我们是如何丢失consistent result 的吗?
【问题讨论】:
标签: scala concurrency functional-programming future