请问,这两种定义接收器的方法有什么区别[RandomCdr,Future [Done]
Flow[RandomCdr]
.grouped(bulkSize)
.flatMapConcat{ (bulk : Seq[RandomCdr]) =>
Source.fromFuture(collection.flatMap(_.insert[RandomCdr](false)(randomCdrWriter,ec).many(bulk)(ec))(ec))
}
.toMat(Sink.ignore)(Keep.right)
Flow[RandomCdr]
.grouped(bulkSize)
.map((bulk : Seq[RandomCdr]) => collection.flatMap(_.insert[RandomCdr](false)(randomCdrWriter,ec).many(bulk)(ec))(ec))
.toMat(Sink.ignore)(Keep.right)
返回Future [T]的函数collection.flatMap(_.insert[RandomCdr](false)(randomCdrWriter,ec).many(bulk)(ec))(ec)
是reactivemongo驱动程序
答案 0 :(得分:0)
第一段摘录
此处每个传入的批量将转换为TypeError: 'float' object cannot be interpreted as an index
,并且所述Future
将在您提供的执行上下文中运行。只有在这一点上,下一个批量将通过生成另一个Future
进行处理,依此类推。
基本上,期货按顺序运行。这与
的行为相似Future
第二段摘录
此处每个传入的批量将转换为Flow[RandomCdr]
.grouped(bulkSize)
.mapAsync(parallelism = 1){ (bulk : Seq[RandomCdr]) =>
collection.flatMap(_.insert[RandomCdr](false)(randomCdrWriter,ec).many(bulk)(ec))(ec)
}
.toMat(Sink.ignore)(Keep.right)
,它将在您提供的执行上下文中运行。 Future
将立即传递给Future
,其引用将被丢弃。
使用这种方法无法控制同时运行多少Sink.ignore
个。因此,不推荐这种方法。
如果您正在寻找改进的并行性,请考虑使用上面显示的Future
,并调整并行度参数。