def reopen_read_loop

mylsm-lsm-store@0.3.2.0 · src/Db.bend:450

import mylsm-lsm-store@0.3.2.0/src/Db.bend as Db
import Base
import mylsm-lsm-store@0.3.2.0/src/Fs.bend as Fs
import mylsm-lsm-store@0.3.2.0/src/Decimal.bend as Decimal

450# Chunked WAL reader (SstStream.stream_loop shape): the freshly read chunk
451# re-enters as the `pending` parameter, so every match scrutinee is a
452# parameter or field and the loop is a single self-recursive def.
453def reopen_read_loop(chunks_left: Nat, +path: String, +offset: Nat, +acc: String, pending: Maybe<&2, ReChunk>) -> IO(Result<&1, &1, U32 & String, String>):
454  match chunks_left pending:
455    case 0n _:
456      IO.pure(Result<&1, &1, U32 & String, String>, Fail{(U32.from_nat(7n), "wal exceeds streaming read limit")})
457    case 1n+rest None{}:
458      do IO<Result<&1, &1, U32 & String, String>>:
459        raw : String <- IO.try(String, Fs.read_utf8_chunk(path, offset, reopen_chunk_chars()))
460        chunk : ReChunk <- IO.try(ReChunk, IO.pure(Result<&1, &1, U32 & String, ReChunk>, reopen_chunk_parse(Decimal.parse_semicolon(raw, reopen_chunk_chars()))))
461        reopen_read_loop(rest, path, offset, acc, Some{chunk})
462    case 1n+rest Some{ReChunk{bytes, text}}:
463      match bytes:
464        case 0n:
465          IO.pure(Result<&1, &1, U32 & String, String>, Done{acc})
466        case 1n+more:
467          reopen_read_loop(rest, path, Nat.add(offset, 1n+more), acc ++ text, None{})

Uses (19)

Used by (1)