def loop
mylsm-lsm-store@0.6.0.1 · src/transfer/BackupIo.bend:174
import mylsm-lsm-store@0.6.0.1/src/transfer/BackupIo.bend as BackupIo
import Base
import mylsm-lsm-store@0.6.0.1/src/transfer/Backup.bend as Backup
import mylsm-lsm-store@0.6.0.1/src/Fs.bend as Fs
174
175def loop(fuel: Nat, +destination: String, +temporary: String, state: State) -> IO(Result<&1, &1, Error, Unit>):
176 match fuel:
177 case 0n:
178 match state:
179 case Need{file, _}: close.failed(file, temporary, (7, "backup stream exceeded its transition budget"))
180 case Output{file, _}: close.failed(file, temporary, (7, "backup stream exceeded its transition budget"))
181 case Written{(file, _), _}:
182 do IO<Result<&1, &1, Error, Unit>>:
183 _closed : Unit <- File.close(file)
184 cleanup(temporary)
185 return Fail{Io{7, "backup stream exceeded its transition budget"}}
186 case 1n+rest:
187 match state:
188 case Need{file, stream}:
189 loop(rest, destination, temporary, Output{file, Backup.next(stream)})
190 case Output{file, result}:
191 match result:
192 case Fail{_}:
193 close.failed(file, temporary, (22, "backup encoder rejected its snapshot"))
194 case Done{Backup.End{}}:
195 publish.closed(destination, temporary, file, Done{Unit{}})
196 case Done{Backup.Chunk{stream, bytes}}:
197 do IO<Result<&1, &1, Error, Unit>>:
198 written : File & Result<&1, &1, U32 & String, Unit> <- Fs.write_bytes(file, bytes)
199 loop(rest, destination, temporary, Written{written, stream})
200 case Written{pair, stream}:
201 match pair:
202 case (file, Fail{error}): close.failed(file, temporary, error)
203 case (file, Done{Unit{}}): loop(rest, destination, temporary, Need{file, stream})