def drain
bend-kit-llm@0.13.0.1 · llm.bend:434
import bend-kit-llm@0.13.0.1/llm.bend as Llm
import Base
import bend-kit-http@0.38.1.1/http.bend as Http
import bend-kit-bytes@0.3.3.0/bytes.bend as Bytes
434
435def drain(f: Nat, x: Http.Stream & Result<&1, &1, Http.Err, Maybe<&1, Bytes.Bytes>>, acc: Bytes.Bytes) -> IO(Bytes.Bytes):
436 match f:
437 case 0n:
438 (h, r) = x
439 do IO<Bytes.Bytes>:
440 Http.stream.close(h)
441 return acc
442 case 1n+g:
443 (h, r) = x
444 match r:
445 case Fail{e}:
446 do IO<Bytes.Bytes>:
447 Http.stream.close(h)
448 return acc
449 case Done{m}:
450 match m:
451 case None{}:
452 do IO<Bytes.Bytes>:
453 Http.stream.close(h)
454 return acc
455 case Some{b}:
456 do IO<Bytes.Bytes>:
457 y : Http.Stream & Result<&1, &1, Http.Err, Maybe<&1, Bytes.Bytes>> <- Http.stream.read(h)
458 drain(g, y, Bytes.append(acc, b))