def scan.loop
mylsm-lsm-store@0.6.0.1 · src/scan/SstCursor.bend:222
import mylsm-lsm-store@0.6.0.1/src/scan/SstCursor.bend as SstCursor
import Base
import mylsm-lsm-store@0.6.0.1/src/scan/ByteBlockReader.bend as ByteBlockReader
222def scan.loop(fuel: Nat, state: ScanState) -> IO(Step):
223 match fuel:
224 case 0n: scan.exhausted(state)
225 case 1n+rest:
226 match state:
227 case ScanNeed{reader, bounds}:
228 do IO<Step>:
229 result : Result<&1, &1, U32 & String, ByteBlockReader.Step> <-
230 ByteBlockReader.next(reader)
231 scan.loop(rest, ScanRead{result, bounds})
232 case ScanRead{result, bounds}:
233 match result:
234 case Fail{error}:
235 IO.pure(Step, Error{error})
236 case Done{ByteBlockReader.End{}}:
237 IO.pure(Step, End{})
238 case Done{ByteBlockReader.Block{reader, entries}}:
239 scan.loop(rest, ScanBlock{reader, entries, bounds})
240 case ScanBlock{reader, entries, bounds}:
241 match entries:
242 case Nil{}:
243 scan.loop(rest, ScanNeed{reader, bounds})
244 case Con{entry, tail}:
245 scan.entry(entry, ByteBlockReader.EntryReady{reader, tail}, bounds)