【发布时间】:2014-10-04 18:08:09
【问题描述】:
我正在将使用 ReactiveMongo 的应用程序与旧版应用程序集成。
因为,我必须在某些时候维护遗留应用程序接口,我必须阻止和/或将我的代码转换为指定的接口类型。我将该代码简化为下面的示例。
有没有比 getChunks 更好的方法来消耗所有输出类型为 List 的 Enumerator?标准做法是什么?
implicit def legacyAdapter[TInput,TResult]
(block: Future[Enumerator[TInput]])
(implicit translator : (TInput => TResult),
executionContext:ExecutionContext,
timeOut : Duration): List[TResult] = {
val iter = Iteratee.getChunks[TResult]
val exhaustFuture = block.flatMap{
enumy => { enumy.map(i => translator(i) ).run(iter) }
}
val r = Await.result(exhaustFuture , timeOut)
r
}
【问题讨论】:
标签: scala playframework-2.0 reactivemongo