Stream.Stream.loop: def of bend-kube-runtime@0.2.0.0 Import: import bend-kube-runtime@0.2.0.0/src/stream.bend as Stream Lines 87-121 of bend-kube-runtime@0.2.0.0/src/stream.bend: https://jend.leeeet.dev/read.txt?path=bend-kube-runtime@0.2.0.0/src/stream.bend&start_line=87&end_line=121 import Base import bend-kube-runtime@0.2.0.0/src/client.bend as Cl # Reads until the body ends, folding the body into st; bad holds the body # of a refusal. Answers the socket and the outcome. def Stream.loop(~S: Type, ~on: S -> List<&2, U32> -> IO(S), fuel: Nat, ev: SEv, st: S, +bad: List<&2, U32>, +ms: U32) -> IO(Socket & Res(S)): match fuel ev: case 0n SGot{s, rp, r}: IO.pure(Socket & Res(S), (s, Fail{Cl.KNet{0, "stream: too long"}})) case 0n SChk{s, r, b, er, ok, h, em, fin, c}: IO.pure(Socket & Res(S), (s, Fail{Cl.KNet{0, "stream: too long"}})) case 1n+f SGot{s, rp, Done{+bs}}: Stream.loop(~S, ~on, f, Stream.fed(s, bs, rp), st, bad, ms) case 1n+f SGot{s, rp, Fail{(c, m)}}: IO.pure(Socket & Res(S), (s, Fail{Cl.KNet{c, "stream: recv: " ++ m}})) case 1n+f SChk{s, r, b, Some{m}, ok, h, em, fin, c}: IO.pure(Socket & Res(S), (s, Fail{Cl.KNet{0, "stream: " ++ m}})) case 1n+f SChk{s, +r, b, None{}, True{}, h, False{}, fin, +c}: IO.bind(S, Socket & Res(S), on(st, b), st2 => Stream.loop(~S, ~on, f, SChk{s, r, Nil{}, None{}, True{}, True{}, True{}, fin, c}, st2, bad, ms)) case 1n+f SChk{s, r, b, None{}, True{}, h, True{}, True{}, c}: IO.pure(Socket & Res(S), (s, Done{st})) case 1n+f SChk{s, +r, b, None{}, True{}, h, True{}, False{}, c}: IO.bind(Socket & Result<&1, &1, U32 & String, List<&2, U32>>, Socket & Res(S), Stream.recv(s, ms), p => Stream.loop(~S, ~on, f, SEv.got(p, r), st, bad, ms)) case 1n+f SChk{s, r, b, None{}, False{}, True{}, em, True{}, +c}: IO.pure(Socket & Res(S), (s, Fail{Stream.refused(c, List.append(&2, U32, bad, b))})) case 1n+f SChk{s, +r, b, None{}, False{}, True{}, em, False{}, c}: IO.bind(Socket & Result<&1, &1, U32 & String, List<&2, U32>>, Socket & Res(S), Stream.recv(s, ms), p => Stream.loop(~S, ~on, f, SEv.got(p, r), st, List.append(&2, U32, bad, b), ms)) case 1n+f SChk{s, r, b, None{}, False{}, False{}, em, True{}, c}: IO.pure(Socket & Res(S), (s, Fail{Cl.KNet{0, "stream: connection closed before a response"}})) case 1n+f SChk{s, +r, b, None{}, False{}, False{}, em, False{}, c}: IO.bind(Socket & Result<&1, &1, U32 & String, List<&2, U32>>, Socket & Res(S), Stream.recv(s, ms), p => Stream.loop(~S, ~on, f, SEv.got(p, r), st, bad, ms)) Uses (22): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=IO https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=IO.bind https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=IO.pure https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=List https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=List.append https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Maybe https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Pair https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Result https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Sigma https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Socket https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=String https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=String.append https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32 https://jend.leeeet.dev/definition.txt?path=bend-kube-runtime@0.2.0.0/src/client.bend&name=KErr https://jend.leeeet.dev/definition.txt?path=bend-kube-runtime@0.2.0.0/src/stream.bend&name=Res https://jend.leeeet.dev/definition.txt?path=bend-kube-runtime@0.2.0.0/src/stream.bend&name=SEv https://jend.leeeet.dev/definition.txt?path=bend-kube-runtime@0.2.0.0/src/stream.bend&name=SEv.got https://jend.leeeet.dev/definition.txt?path=bend-kube-runtime@0.2.0.0/src/stream.bend&name=Stream.fed https://jend.leeeet.dev/definition.txt?path=bend-kube-runtime@0.2.0.0/src/stream.bend&name=Stream.recv https://jend.leeeet.dev/definition.txt?path=bend-kube-runtime@0.2.0.0/src/stream.bend&name=Stream.refused