我試圖通過從我的數據源遞歸讀取數據來生成一系列切片。遞歸序列生成
let rec read stream startFrom (conn : IEventStoreConnection) =
seq {
let size = 10000
let slice = conn.ReadStreamEventsForwardAsync(stream, startFrom, size, true).Result
Console.WriteLine("Events in slice: " + slice.Events.Count().ToString())
if (slice.IsEndOfStream) then
yield slice
else
yield! read stream (startFrom + 1 * size) conn
}
let slices = read "stream-name" 0 conn
Console.WriteLine("TOTAL slices in sequence: " + (Seq.length slices).ToString());
我期待的序列包含三個項目,但它似乎只返回一個,最後一個。
Events in slice: 10000
Events in slice: 10000
Events in slice: 4501
TOTAL slices in sequence: 1
爲什麼我的遞歸調用的結果也被忽略了?範圍的東西?
所以想想會發生什麼 - 如果你不在流的盡頭,那麼你就會緩慢地走到最後。只有流的結尾纔會返回某些內容。 – 2014-10-05 11:50:45