def claim

bend-kit-runner@0.13.0.1 · runner.bend:1274

import bend-kit-runner@0.13.0.1/runner.bend as Runner
import Base
import bend-kit-bytes@0.3.3.0/bytes.bend as Bytes
import bend-kit-retry@0.3.0.0/retry.bend as Retry

1274# Starts an attempt for each due ticket while the pool has a free unit; each attempt sends its outcome on the inbox.
1275# fuel bounds the tickets taken, and the fuel left comes back.
1276def claim(~A: Data, ~penc: A -> Bytes.Bytes, ~target: A -> String, ~work: A -> IO(Retry.Outcome), fuel: Nat, +now: Nat, r: Runner<A>) -> IO(Claimed(A)):
1277  match fuel:
1278    case 0n:
1279      IO.pure(Claimed(A), (r, 0n, Done{Unit{}}))
1280    case 1n+n:
1281      Runner{j, +s, p, c, ib, fs} = r
1282      +m = n
1283      claim.pick(~A, ~penc, ~target, ~work, m, now, pick(~A, p, s, now), j, s, c, ib, fs, (r2 => claim(~A, ~penc, ~target, ~work, m, now, r2)))

Uses (13)

Used by (2)