def collect

bend-kit-postgres@0.3.0.0 · postgres.bend:536

import bend-kit-postgres@0.3.0.0/postgres.bend as Postgres
import Base
import bend-kit-postgres@0.3.0.0/codec.bend as Codec

536# After an ErrorResponse the server skips to Sync, so reading on to ReadyForQuery keeps
537# the connection in step. A message that has no place in the reply closes it.
538def collect(fuel: Nat, r: Result<&1, &1, Failure, Conn & Step>) -> IO(Result<&1, &1, Failure, Conn & Reply>):
539  match fuel:
540    case 0n:
541      match r:
542        case Fail{e}:
543          IO.pure(Result<&1, &1, Failure, Conn & Reply>, Fail{e})
544        case Done{(c, s)}:
545          abort(Conn & Reply, c, Malformed{})
546    case 1n+f:
547      match r:
548        case Fail{e}:
549          IO.pure(Result<&1, &1, Failure, Conn & Reply>, Fail{e})
550        case Done{(c, s)}:
551          match s:
552            case Go{a}:
553              do IO<Result<&1, &1, Failure, Conn & Reply>>:
554                m : Result<&1, &1, Failure, Conn & Codec.Back> <- read(c)
555                collect(f, absorbed(a, m))
556            case Stop{a, +status}:
557              finish(c, status, a)
558            case Odd{}:
559              abort(Conn & Reply, c, Malformed{})

Uses (16)

Used by (1)