def go

bend-kit-hairpin@0.14.0.0 · hairpin.bend:393

import bend-kit-hairpin@0.14.0.0/hairpin.bend as Hairpin
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
import bend-kit-retry@0.3.0.0/retry.bend as Retry

393# left: attempts this layer may still make. n: attempts made so far. Each turn follows the plan of the last step.
394def go(~R: Type, ~judge: Result<&1, &1, Http.Err, R> -> Result<&1, &1, Http.Err, R> & Verdict,
395    ~try: Opts -> Call -> Http.Pool -> Maybe<&2, Http.Jar> -> Bytes.Bytes -> IO(Http.Pool & Maybe<&2, Http.Jar> & Result<&1, &1, Http.Err, R>),
396    ~close: R -> IO(Unit),
397    left: Nat, +n: Nat, +o: Opts, +call: Call, +idem: Bool, s: Step<R>) -> IO(Step<R>):
398  match left:
399    case 0n:
400      IO.pure(Step<R>, s)
401    case 1n+rest:
402      Step{pool, jar, br, b, body, last, plan} = s
403      match plan:
404        case Retry.PlanStop{}:
405          IO.pure(Step<R>, Step{pool, jar, br, b, body, last, Retry.PlanStop{}})
406        case Retry.PlanWait{ms}:
407          do IO<Step<R>>:
408            pause(ms)
409            next : Step<R> <- attempt(~R, ~judge, ~try, ~close, o, call, idem, n, Step{pool, jar, br, b, body, last, Retry.PlanStop{}})
410            go(~R, ~judge, ~try, ~close, rest, 1n+n, o, call, idem, next)

Uses (20)

Used by (1)