![](/img/trans.png)
[英]ExecutionContext to use with mapAsync in Akka-Streams
[英]What is the Use Case of `extrapolate` in `Akka-Streams`?
我只是想conflate
,並extrapolate
在akka-streams
。
由於conflate
對我來說完全有意義,我沒有得到extrapolate
的用例。
為什么我們要為下游增加更多的工作——當上游不需要它時?
來自 Scala 文檔:
允許更快的下游獨立於較慢的上游。
舉個例子:
在視頻游戲中,通常至少有兩個“循環”:邏輯/游戲循環和渲染循環。 通常,游戲循環的速率(“滴答速率”)比渲染循環的速率(“幀速率”)慢。 例如,邏輯滴答每秒可能發生 10 次,但幀速率通常應至少為每秒 60 幀。 為了在滴答聲之間呈現一些東西,游戲開發者使用外推法或插值法。 您可能已經猜到,外推函數非常適合外推。 這是一個滴答率為每秒 10 滴答且沒有幀速率限制的示例:
Source.tick(0.millis, 100.millis, 0)
.scan(intialGameState) { (g, _) => tick(g) }
.extrapolate(extrapolateFn)
.runForeach(render)
現在extrapolateFn
只需要返回一個迭代器,根據需要提供外推游戲狀態:
def extrapolateFn(g: GameState) = Iterator.continually {
// Compute how long it has been since `g` was created
// Advance the state by that amount of time
// Return the new state
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.