~/bend-docscommunity

runner.bend relies on unsafe/foreign

raw source on the hub · import bend-kit-runner@0.16.0.1/runner.bend as Runner

Durable job runner: a journaled scheduler queue, bounded by a resources pool, with retry and a breaker per target. Source: https://github.com/paymog/bend-kit/tree/main/runner

13 imports
import Base
import bend-kit-bytes@0.3.3.0/bytes.bend as Bytes
import bend-kit-journal@0.3.1.1/journal.bend as J
import bend-kit-scheduler@0.4.3.0/queue.bend as Q
import bend-kit-resources@0.1.0.0/resources.bend as Res
import bend-kit-retry@0.3.0.0/retry.bend as Retry
import bend-kit-time@0.3.0.0/time.bend as Time
import bend-kit-collections@0.1.5.0/heap.bend as H
import bend-kit-collections@0.1.5.0/omap.bend as O
import bend-kit-collections@0.1.5.0/hmap.bend as M
import bend-kit-collections@0.1.5.0/LAWS.bend as CL
import bend-kit-collections@0.1.5.0/PROOF.bend as CP
import bend-kit-files@0.4.0.0/files.bend as Files

Types

type Why source · line 18 · raw

Data

Why retry gave up on a ticket: its budget was spent, its deadline passed, its failure must not repeat, or another try would repeat its failure.

type Dead source · line 26 · raw

@-A:Data -> Data

A ticket that retry gave up on, with its payload, and when it gave up (wall-clock ms). It stays until Revive, Cancel, or Purge takes it.

type Op source · line 35 · raw

@-A:Data -> Data

One durable transition. Each one is one journal record, appended before the state changes. Select: the queue's select at now. Replay runs it at the same now, so it takes the same ticket. Requeue: the attempt failed; it counts one failure. Defer: the breaker held the ticket back; no attempt ran. Abandon: retry gave up at at; the running ticket becomes dead. Revive: a dead ticket is pending again at deadline, with a new budget. Purge: the dead tickets abandoned before before are dropped. PurgeAll: every dead ticket is dropped. Break: the breaker of target changed to state.

type Try source · line 49 · raw

Data

The failed attempts of a ticket, and its first deadline, from which the policy deadline counts.

type State source · line 68 · raw

@-A:Data -> Data

The durable state: the queue, the tries, the dead tickets, and the breakers.

type Rec source · line 312 · raw

@-A:Data -> Data

A journal record. Compaction writes one Snap of the whole state; every other record is one op.

type Pick source · line 337 · raw

@-A:Data -> Type

Picked: a due ticket and one unit of the pool for it. Idle: no due ticket, or no free unit; the pool is unchanged.

type Rd source · line 629 · raw

Type

A snapshot reader: the record, and the offset of the next field.

type Config source · line 1072 · raw

Data

policy: retry's policy for each ticket. circuit: the breaker of each target. idle: ms that drain waits when no attempt started. compact: tick compacts the journal once records past this many octets were appended since open or the last compaction; 0 never.

type Log source · line 1076 · raw

Type

The journal, its path, its file cap, and its length at open or at the last compaction.

type Flight source · line 1080 · raw

@-A:Data -> Type

An attempt that runs: its unit of the pool, the budget that admit left, and its target.

type Msg source · line 1087 · raw

@-A:Data -> Type

A message to the fiber that owns the runner. Ended: an attempt finished. Add and Drop: another fiber asks for an enqueue or a cancel.

type Runner source · line 1094 · raw

@-A:Data -> Type

An open runner. Replaying its journal gives its state; its pool bounds the attempts that run at once. Each attempt sends its outcome, and each other fiber its ask, on inbox. flights are the attempts that run.

type Swap source · line 1484 · raw

Type

Kept: compaction failed before the rename, and the old journal stands. Stranded: the rename happened, but the new journal did not open. Moved: the journal at path is the snapshot.

Definitions

def Tries source · line 53 · raw

Data

A Try for each ticket that is not yet complete, cancelled, or dead, by ticket id.

def Breakers source · line 57 · raw

Data

The breaker state of each target that has one, by target. An absent target is closed with no failures.

def dead.hash source · line 60 · raw

@i:Nat -> U32

def Graves source · line 64 · raw

@-A:Data -> Data

The dead tickets, by ticket id.

def new source · line 71 · raw

@-A:Data -> State<A>

def queue source · line 74 · raw

@-A:Data -> @s:State<A> -> 0x77b88a2c45e79ff162b14cf8d6ee4112/queue.State<A>

def tries source · line 78 · raw

@-A:Data -> @s:State<A> -> Tries

def dead source · line 83 · raw

@-A:Data -> @s:State<A> -> Graves(A)

The dead tickets, by id. A Revive of one makes it pending again; a Cancel or a Purge drops it.

def breakers source · line 87 · raw

@-A:Data -> @s:State<A> -> Breakers

def dead.list.entries source · line 106 · raw

@-A:Data -> @es:List<&2, 0x55289dd95dde91bbc62b3e414066cf83/hmap.Entry<Nat, Dead<A>>> -> @acc:List<&2, Dead<A>> -> List<&2, Dead<A>>

def dead.list.go source · line 113 · raw

@-A:Data -> @ds:Graves(A) -> @acc:List<&2, Dead<A>> -> List<&2, Dead<A>>

def dead.list source · line 123 · raw

@-A:Data -> @ds:Graves(A) -> List<&2, Dead<A>>

The dead tickets, in no set order.

def dead.old.keep source · line 126 · raw

@-A:Data -> @old:Bool -> @+i:Nat -> @rest:List<&2, Nat> -> List<&2, Nat>

def dead.old source · line 134 · raw

@-A:Data -> @ds:List<&2, Dead<A>> -> @+t:Nat -> List<&2, Nat>

The ids of the dead tickets abandoned before t.

def tries.drop source · line 154 · raw

@ts:Tries -> @+i:Nat -> Tries

def tries.get source · line 157 · raw

@ts:Tries -> @+i:Nat -> Maybe<&2, Try>

def tries.bump.got source · line 160 · raw

@m:Maybe<&2, Try> -> @ts:Tries -> @+i:Nat -> Tries

def tries.bump source · line 167 · raw

@+ts:Tries -> @+i:Nat -> Tries

def brk.got source · line 172 · raw

@r:Pair(Breakers, 0x14e48621ef66156b0eb652524b8594d4/retry.State) -> 0x14e48621ef66156b0eb652524b8594d4/retry.State

def brk.get source · line 177 · raw

@-A:Data -> @s:State<A> -> @key:String -> 0x14e48621ef66156b0eb652524b8594d4/retry.State

The breaker state of target key.

def brk.state source · line 180 · raw

@br:0x14e48621ef66156b0eb652524b8594d4/retry.Breaker -> @old:0x14e48621ef66156b0eb652524b8594d4/retry.State -> 0x14e48621ef66156b0eb652524b8594d4/retry.State

def brk.nats source · line 187 · raw

@a:List<&2, Nat> -> @b:List<&2, Nat> -> Bool

def brk.same source · line 196 · raw

@a:0x14e48621ef66156b0eb652524b8594d4/retry.State -> @b:0x14e48621ef66156b0eb652524b8594d4/retry.State -> Bool

def calm.state source · line 207 · raw

@b:0x14e48621ef66156b0eb652524b8594d4/retry.State -> 0x14e48621ef66156b0eb652524b8594d4/retry.State

def calm.map source · line 216 · raw

@m:Breakers -> Breakers

def calm source · line 226 · raw

@-A:Data -> @s:State<A> -> State<A>

The probes of a half-open breaker died with the process that ran them, so open counts none in flight.

def step.enqueued source · line 232 · raw

@-A:Data -> @r:Pair(0x77b88a2c45e79ff162b14cf8d6ee4112/queue.State<A>, Nat) -> @ts:Tries -> @ds:Graves(A) -> @bs:Breakers -> @d:Nat -> State<A>

def step.selected source · line 236 · raw

@-A:Data -> @r:Pair(0x77b88a2c45e79ff162b14cf8d6ee4112/queue.State<A>, Maybe<&2, 0x77b88a2c45e79ff162b14cf8d6ee4112/queue.Ticket<A>>) -> @ts:Tries -> @ds:Graves(A) -> @bs:Breakers -> State<A>

def step.requeued source · line 240 · raw

@-A:Data -> @r:Pair(0x77b88a2c45e79ff162b14cf8d6ee4112/queue.State<A>, Bool) -> @ts:Tries -> @ds:Graves(A) -> @bs:Breakers -> State<A>

def step.completed source · line 245 · raw

@-A:Data -> @r:Pair(0x77b88a2c45e79ff162b14cf8d6ee4112/queue.State<A>, Maybe<&2, 0x77b88a2c45e79ff162b14cf8d6ee4112/queue.Ticket<A>>) -> @ts:Tries -> @ds:Graves(A) -> @bs:Breakers -> State<A>

Complete takes the ticket from the running list only: O(running), not O(pending).

def step.broke source · line 263 · raw

@bs:Breakers -> @k:String -> @b:0x14e48621ef66156b0eb652524b8594d4/retry.State -> Breakers

A closed breaker with no failures reads the same as an absent one, so it leaves the map.

def pick.took source · line 341 · raw

@-A:Data -> @r:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Reserve -> @t:0x77b88a2c45e79ff162b14cf8d6ee4112/queue.Ticket<A> -> Pick<A>

def pick.due source · line 348 · raw

@-A:Data -> @m:Maybe<&2, 0x77b88a2c45e79ff162b14cf8d6ee4112/queue.Ticket<A>> -> @p:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Pool -> Pick<A>

def pick.sel source · line 355 · raw

@-A:Data -> @r:Pair(0x77b88a2c45e79ff162b14cf8d6ee4112/queue.State<A>, Maybe<&2, 0x77b88a2c45e79ff162b14cf8d6ee4112/queue.Ticket<A>>) -> @p:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Pool -> Pick<A>

def budget.of source · line 367 · raw

@+attempts:Nat -> @t:Maybe<&2, Try> -> @d:Maybe<&2, Nat> -> 0x14e48621ef66156b0eb652524b8594d4/retry.Budget

The budget left for ticket i: the policy's attempts less its failures, until its start plus the policy deadline.

def budget source · line 376 · raw

@p:0x14e48621ef66156b0eb652524b8594d4/retry.Policy -> @t:Maybe<&2, Try> -> 0x14e48621ef66156b0eb652524b8594d4/retry.Budget

def fails source · line 381 · raw

@t:Maybe<&2, Try> -> Nat

The failures so far: the index of the next retry.

def gave source · line 389 · raw

@b:0x14e48621ef66156b0eb652524b8594d4/retry.Budget -> Why

Why retry stopped a transient failure: no attempt is left, or the next wait would reach the deadline.

def stopped source · line 398 · raw

@-A:Data -> @o:0x14e48621ef66156b0eb652524b8594d4/retry.Outcome -> @b:0x14e48621ef66156b0eb652524b8594d4/retry.Budget -> @+id:Nat -> @+now:Nat -> Op<A>

A settled attempt completes its ticket; retry gave up at now on any other.

def after.plan source · line 411 · raw

@-A:Data -> @pl:0x14e48621ef66156b0eb652524b8594d4/retry.Plan -> @o:0x14e48621ef66156b0eb652524b8594d4/retry.Outcome -> @b:0x14e48621ef66156b0eb652524b8594d4/retry.Budget -> @+id:Nat -> @+now:Nat -> Op<A>

def after source · line 420 · raw

@-A:Data -> @+o:0x14e48621ef66156b0eb652524b8594d4/retry.Outcome -> @p:0x14e48621ef66156b0eb652524b8594d4/retry.Policy -> @+b:0x14e48621ef66156b0eb652524b8594d4/retry.Budget -> @+id:Nat -> @+n:Nat -> @+now:Nat -> @+r:Nat -> Op<A>

The record after an attempt of ticket id ends at now with o: requeue at now plus retry's wait, complete when o is settled, or abandon when retry gave up.

def brk.after source · line 424 · raw

@+circ:0x14e48621ef66156b0eb652524b8594d4/retry.Circuit -> @old:0x14e48621ef66156b0eb652524b8594d4/retry.State -> @+now:Nat -> @o:0x14e48621ef66156b0eb652524b8594d4/retry.Outcome -> 0x14e48621ef66156b0eb652524b8594d4/retry.Breaker

A target's breaker after an attempt ends at now with o.

def until source · line 428 · raw

@br:0x14e48621ef66156b0eb652524b8594d4/retry.Breaker -> @+now:Nat -> Nat

When an open breaker lets attempts start again.

def held source · line 440 · raw

@-A:Data -> @why:0x14e48621ef66156b0eb652524b8594d4/retry.Deny -> @br:0x14e48621ef66156b0eb652524b8594d4/retry.Breaker -> @+id:Nat -> @+now:Nat -> Op<A>

The record for a ticket that admit refused: Defer to when the breaker may admit, or Abandon when its budget is spent or late.

def why.code source · line 453 · raw

@w:Why -> Nat

def W source · line 464 · raw

Nat

def put.u64 source · line 468 · raw

@b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> @+at:U32 -> @+n:Nat -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes

Nat fields hold values under 2^64.

def snap.u32 source · line 474 · raw

@out:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> @+v:U32 -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes

def snap.u64 source · line 477 · raw

@out:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> @+n:Nat -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes

def snap.chars source · line 480 · raw

@s:String -> @out:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes

def snap.key source · line 488 · raw

@out:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> @+k:String -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes

A target is a u32 count of chars, then each char as a u32.

def snap.nats source · line 491 · raw

@xs:List<&2, Nat> -> @out:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes

def snap.brk source · line 499 · raw

@out:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> @b:0x14e48621ef66156b0eb652524b8594d4/retry.State -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes

A breaker state is a u32 kind. 0 is closed: a u32 count, then each failure as a u64. 1 is open: until. 2 is half-open: busy.

def get.field source · line 533 · raw

@m:Maybe<&2, U32> -> U32

def get.u32 source · line 540 · raw

@r:Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, Maybe<&2, U32>) -> Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, U32)

def get.hi source · line 544 · raw

@+lo:U32 -> @r:Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, Maybe<&2, U32>) -> Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, Nat)

def get.lo source · line 548 · raw

@+at:U32 -> @r:Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, Maybe<&2, U32>) -> Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, Nat)

def get.u64 source · line 553 · raw

@b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> @+at:U32 -> Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, Nat)

def snap.payload source · line 563 · raw

@out:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> @p:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes

def snap.tries source · line 585 · raw

@ts:Tries -> @out:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes

def snap.brks source · line 608 · raw

@xs:List<&2, Sigma<&2, &2, String, _ => 0x14e48621ef66156b0eb652524b8594d4/retry.State>> -> @out:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes

def Dec source · line 633 · raw

@-T:Type -> Type

One step of the snapshot decoder. None: a field runs past the record or does not decode.

def Dec.next source · line 636 · raw

@-A:Type -> @-B:Type -> @m:Maybe<&1, Pair(Rd, A)> -> @f:(@_:A -> Dec(B)) -> Maybe<&1, Pair(Rd, B)>

def Dec.bind source · line 643 · raw

@-A:Type -> @-B:Type -> @m:Dec(A) -> @f:(@_:A -> Dec(B)) -> Dec(B)

def Dec.pure source · line 646 · raw

@-A:Type -> @x:A -> Dec(A)

def Dec.fail source · line 649 · raw

@-A:Type -> Dec(A)

def rd.u32.of source · line 652 · raw

@m:Maybe<&2, U32> -> @b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> @+at:U32 -> Maybe<&1, Pair(Rd, U32)>

def rd.u32.got source · line 659 · raw

@+at:U32 -> @r:Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, Maybe<&2, U32>) -> Maybe<&1, Pair(Rd, U32)>

def rd.u32.at source · line 663 · raw

@r:Rd -> Maybe<&1, Pair(Rd, U32)>

def rd.u32 source · line 667 · raw

Dec(U32)

def rd.u64.of source · line 670 · raw

@+lo:U32 -> @+hi:U32 -> Nat

def rd.u64 source · line 673 · raw

Dec(Nat)

def rd.cut.got source · line 679 · raw

@+at:U32 -> @+n:U32 -> @r:Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> Maybe<&1, Pair(Rd, 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes)>

def rd.cut.if source · line 683 · raw

@ok:Bool -> @b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> @+at:U32 -> @+n:U32 -> Maybe<&1, Pair(Rd, 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes)>

def rd.cut.at source · line 690 · raw

@+n:U32 -> @r:Rd -> Maybe<&1, Pair(Rd, 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes)>

def rd.cut source · line 695 · raw

@+n:U32 -> Dec(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes)

The next n octets.

def rd.flag.of source · line 698 · raw

@+m:U32 -> Dec(Bool)

def rd.flag source · line 702 · raw

Dec(Bool)

A u32 flag: 1 is True, 0 is False, and any other value fails.

def rd.payload source · line 705 · raw

@-A:Data -> @+i:Nat -> @+d:Nat -> @m:Maybe<&2, A> -> Dec(0x77b88a2c45e79ff162b14cf8d6ee4112/queue.Ticket<A>)

def rd.tries source · line 750 · raw

@+fuel:Nat -> @node:Bool -> Dec(0x55289dd95dde91bbc62b3e414066cf83/omap.OMap<Nat, Try>)

def rd.why source · line 768 · raw

@+c:U32 -> Dec(Why)

def rd.wf source · line 856 · raw

@-A:Data -> @ok:Bool -> @ds:Graves(A) -> Dec(Graves(A))

The trie, when it is well formed as the never-selected laws assume.

def rd.chars source · line 864 · raw

@+fuel:Nat -> @end:Bool -> @+n:U32 -> Dec(String)

Each rd.* sequence reader takes the count or flag already read. fuel bounds its length: every item holds at least 4 octets.

def rd.key source · line 877 · raw

@+fuel:Nat -> Dec(String)

def rd.nats source · line 882 · raw

@+fuel:Nat -> @end:Bool -> @+n:U32 -> Dec(List<&2, Nat>)

def rd.closed source · line 895 · raw

@+fuel:Nat -> Dec(0x14e48621ef66156b0eb652524b8594d4/retry.State)

def rd.brk.of source · line 901 · raw

@+fuel:Nat -> @+kind:U32 -> Dec(0x14e48621ef66156b0eb652524b8594d4/retry.State)

def rd.brk source · line 906 · raw

@+fuel:Nat -> Dec(0x14e48621ef66156b0eb652524b8594d4/retry.State)

def rd.break source · line 909 · raw

@-A:Data -> @+fuel:Nat -> Dec(Op<A>)

def rd.brks source · line 915 · raw

@+fuel:Nat -> @more:Bool -> @acc:Map<&2, 0x14e48621ef66156b0eb652524b8594d4/retry.State> -> Dec(Map<&2, 0x14e48621ef66156b0eb652524b8594d4/retry.State>)

def rd.done source · line 945 · raw

@-T:Data -> @+len:U32 -> @m:Maybe<&1, Pair(Rd, T)> -> Maybe<&2, T>

The value read, when the reader ended at len, the record's end.

def decode.abandon source · line 953 · raw

@-A:Data -> @+a:Nat -> @+c:Nat -> @+e:Nat -> Maybe<&2, Op<A>>

The Abandon of ticket a at e whose why.code is c, or None for any other code.

def decode.small source · line 959 · raw

@-A:Data -> @ok:Bool -> @+tag:U32 -> @+a:Nat -> @+c:Nat -> Maybe<&2, Op<A>>

def decode.long source · line 973 · raw

@-A:Data -> @ok:Bool -> @+a:Nat -> @+c:Nat -> @r:Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, Nat) -> Maybe<&2, Op<A>>

def decode.payload source · line 981 · raw

@-A:Data -> @m:Maybe<&2, A> -> @+d:Nat -> Maybe<&2, Op<A>>

def decode.c.if source · line 988 · raw

@-A:Data -> @abandon:Bool -> @+tag:U32 -> @+len:U32 -> @+a:Nat -> @+c:Nat -> @b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Maybe<&2, Op<A>>

def decode.snapped source · line 1039 · raw

@-A:Data -> @m:Maybe<&2, State<A>> -> Maybe<&2, Rec<A>>

def decode.did source · line 1046 · raw

@-A:Data -> @m:Maybe<&2, Op<A>> -> Maybe<&2, Rec<A>>

def Out source · line 1083 · raw

@-X:Type -> Type

def Claimed source · line 1098 · raw

@-A:Data -> Type

The runner, the claim fuel left, and the first error.

def Ran source · line 1101 · raw

@-A:Data -> Type

def clock source · line 1105 · raw

IO(Nat)

Wall-clock ms since the Unix epoch. Deadlines must keep their meaning across a restart.

def first source · line 1110 · raw

@a:Out(Unit) -> @b:Out(Unit) -> Out(Unit)

def log.appended source · line 1117 · raw

@+path:String -> @+limit:U32 -> @+base:U32 -> @x:Pair(0x67e4e1344805cb419bb08fd62348d5e5/journal.Journal, Out(Unit)) -> Pair(Log, Out(Unit))

def log.append source · line 1121 · raw

@l:Log -> @p:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> IO(Pair(Log, Out(Unit)))

def log.close source · line 1127 · raw

@l:Log -> IO(Unit)

def log.of source · line 1132 · raw

@j:0x67e4e1344805cb419bb08fd62348d5e5/journal.Journal -> @+max:U32 -> @path:String -> @+limit:U32 -> Log

The journal reads with limit as its record cap, so that a snapshot fits; appends keep max.

def enqueue.done source · line 1151 · raw

@-A:Data -> @+id:Nat -> @y:Ran(A) -> Pair(Runner<A>, Out(Nat))

def inbox source · line 1185 · raw

@-A:Data -> @r:Runner<A> -> Pair(Runner<A>, Chan(Msg<A>))

The runner back, and its inbox. Another fiber passes the inbox to ask.enqueue and ask.cancel.

def ask.answer source · line 1189 · raw

@-X:Type -> @m:Maybe<&1, Out(X)> -> Out(X)

def ask.sent source · line 1196 · raw

@-A:Data -> @-X:Type -> @x:Result<&1, &1, Msg<A>, Unit> -> @+rep:Chan(Out(X)) -> IO(Out(X))

def ask source · line 1206 · raw

@-A:Data -> @-X:Type -> @+ib:Chan(Msg<A>) -> @m:(@_:Chan(Out(X)) -> Msg<A>) -> IO(Out(X))

Sends m, built with a new reply channel, on the inbox and waits for the reply.

def ask.enqueue source · line 1214 · raw

@-A:Data -> @+ib:Chan(Msg<A>) -> @+deadline:Nat -> @x:A -> IO(Out(Nat))

From another fiber: adds a job due at deadline, and answers its ticket id once the record is durable. The answer comes when the fiber that owns the runner reads the inbox, in tick or drain.

def ask.cancel source · line 1218 · raw

@-A:Data -> @+ib:Chan(Msg<A>) -> @+id:Nat -> IO(Out(Unit))

From another fiber: cancels ticket id, as cancel does. The answer comes when the owner reads the inbox.

def release.got source · line 1224 · raw

@-A:Data -> @x:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Release -> @j:Log -> @s:State<A> -> @c:Config -> @ib:Chan(Msg<A>) -> @fs:List<&1, Flight<A>> -> Runner<A>

A grant of this runner's pool always fits it, so Kept does not happen.

def release source · line 1231 · raw

@-A:Data -> @r:Runner<A> -> @g:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> Runner<A>

def claim.held source · line 1235 · raw

@-A:Data -> @y:Ran(A) -> @g:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> @next:(@_:Runner<A> -> IO(Claimed(A))) -> IO(Claimed(A))

def claim.tag source · line 1242 · raw

@-A:Data -> @+id:Nat -> @o:0x14e48621ef66156b0eb652524b8594d4/retry.Outcome -> IO(Msg<A>)

def settle.done source · line 1326 · raw

@-A:Data -> @y:Ran(A) -> @g:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> @err:Out(Unit) -> @next:(@_:Runner<A> -> @_:Out(Unit) -> IO(Pair(Runner<A>, Out(Bool)))) -> IO(Pair(Runner<A>, Out(Bool)))

def random source · line 1351 · raw

@r:Out(U32) -> Nat

def take.keep source · line 1358 · raw

@-A:Data -> @m:Maybe<&1, Flight<A>> -> @xs:List<&1, Flight<A>> -> List<&1, Flight<A>>

def take.at source · line 1365 · raw

@-A:Data -> @eq:Bool -> @f:Flight<A> -> @r:Pair(Maybe<&1, Flight<A>>, List<&1, Flight<A>>) -> Pair(Maybe<&1, Flight<A>>, List<&1, Flight<A>>)

def take source · line 1375 · raw

@-A:Data -> @fs:List<&1, Flight<A>> -> @+id:Nat -> Pair(Maybe<&1, Flight<A>>, List<&1, Flight<A>>)

The flight of ticket id, and the other flights.

def asked.failed source · line 1403 · raw

@-A:Data -> @-X:Type -> @+rep:Chan(Out(X)) -> @r:Runner<A> -> @+c:U32 -> @+m:String -> @err:Out(Unit) -> @next:(@_:Runner<A> -> @_:Nat -> @_:Out(Unit) -> IO(Pair(Runner<A>, Out(Bool)))) -> IO(Pair(Runner<A>, Out(Bool)))

Sends the failure to the asker, and keeps it as the round's error.

def asked.fail source · line 1409 · raw

@-A:Data -> @-X:Type -> @+rep:Chan(Out(X)) -> @r:Runner<A> -> @e:Pair(U32, String) -> @err:Out(Unit) -> @next:(@_:Runner<A> -> @_:Nat -> @_:Out(Unit) -> IO(Pair(Runner<A>, Out(Bool)))) -> IO(Pair(Runner<A>, Out(Bool)))

def added source · line 1414 · raw

@-A:Data -> @+rep:Chan(Out(Nat)) -> @y:Pair(Runner<A>, Out(Nat)) -> @err:Out(Unit) -> @next:(@_:Runner<A> -> @_:Nat -> @_:Out(Unit) -> IO(Pair(Runner<A>, Out(Bool)))) -> IO(Pair(Runner<A>, Out(Bool)))

def dropped source · line 1424 · raw

@-A:Data -> @+rep:Chan(Out(Unit)) -> @y:Ran(A) -> @err:Out(Unit) -> @next:(@_:Runner<A> -> @_:Nat -> @_:Out(Unit) -> IO(Pair(Runner<A>, Out(Bool)))) -> IO(Pair(Runner<A>, Out(Bool)))

def merged source · line 1445 · raw

@-A:Data -> @e:Out(Unit) -> @k:Claimed(A) -> Claimed(A)

def empty.heap source · line 1449 · raw

@-A:Data -> @h:0x55289dd95dde91bbc62b3e414066cf83/heap.Heap<0x77b88a2c45e79ff162b14cf8d6ee4112/queue.Ticket<A>> -> Bool

def empty.list source · line 1456 · raw

@-A:Data -> @xs:List<&2, 0x77b88a2c45e79ff162b14cf8d6ee4112/queue.Ticket<A>> -> Bool

def idle source · line 1464 · raw

@-A:Data -> @s:State<A> -> Bool

No ticket is pending or running. Dead tickets wait for a Revive, so they do not count.

def pending source · line 1468 · raw

@-A:Data -> @s:State<A> -> Nat

def flights.none source · line 1473 · raw

@-A:Data -> @fs:List<&1, Flight<A>> -> Pair(List<&1, Flight<A>>, Bool)

The flights back, and whether none runs.

def swap.reopened source · line 1489 · raw

@x:Out(Pair(0x67e4e1344805cb419bb08fd62348d5e5/journal.Journal, Unit)) -> Swap

def swap.renamed source · line 1497 · raw

@+path:String -> @+limit:U32 -> @x:Out(Unit) -> IO(Swap)

The reopen fsyncs the directory, so the rename is durable before the next append.

def swap.written source · line 1506 · raw

@+path:String -> @+tmp:String -> @+limit:U32 -> @x:Pair(0x67e4e1344805cb419bb08fd62348d5e5/journal.Journal, Out(Unit)) -> IO(Swap)

def swap.opened source · line 1518 · raw

@+path:String -> @+tmp:String -> @+limit:U32 -> @x:Out(Pair(0x67e4e1344805cb419bb08fd62348d5e5/journal.Journal, Unit)) -> @snap:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> IO(Swap)

def swap source · line 1528 · raw

@+path:String -> @+limit:U32 -> @snap:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> IO(Swap)

Writes snap as the only record of path.compact, fsyncs it, and renames it over path.

def log.stop source · line 1535 · raw

@j:0x67e4e1344805cb419bb08fd62348d5e5/journal.Journal -> 0x67e4e1344805cb419bb08fd62348d5e5/journal.Journal

def compact.moved source · line 1539 · raw

@x:Swap -> @j:0x67e4e1344805cb419bb08fd62348d5e5/journal.Journal -> @+max:U32 -> @path:String -> @+limit:U32 -> @+base:U32 -> IO(Pair(Log, Out(Unit)))

def compact.done source · line 1559 · raw

@-A:Data -> @x:Pair(Log, Out(Unit)) -> @s:State<A> -> @p:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Pool -> @c:Config -> @ib:Chan(Msg<A>) -> @fs:List<&1, Flight<A>> -> Ran(A)

def tick.ran source · line 1573 · raw

@e:Out(Unit) -> @b:Bool -> Out(Bool)

def tick.compacted source · line 1580 · raw

@-A:Data -> @+b:Bool -> @y:Ran(A) -> Pair(Runner<A>, Out(Bool))

def tick.polled source · line 1607 · raw

@-A:Data -> @x:Poll<&1, &1, Maybe<&1, Msg<A>>, Unit> -> Maybe<&1, Msg<A>>

def tick.wait source · line 1614 · raw

@-A:Data -> @t:Pair(List<&1, Flight<A>>, Bool) -> @j:Log -> @s:State<A> -> @p:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Pool -> @c:Config -> @+ib:Chan(Msg<A>) -> IO(Pair(Runner<A>, Maybe<&1, Msg<A>>))

def tick.next source · line 1628 · raw

@-A:Data -> @r:Runner<A> -> IO(Pair(Runner<A>, Maybe<&1, Msg<A>>))

The next message. While an attempt runs, it waits for one; when none runs, it takes one only when the inbox holds one.

def finished.of source · line 1678 · raw

@-A:Data -> @+quiet:Bool -> @t:Pair(List<&1, Flight<A>>, Bool) -> @j:Log -> @s:State<A> -> @p:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Pool -> @c:Config -> @ib:Chan(Msg<A>) -> Pair(Runner<A>, Bool)

def finished source · line 1684 · raw

@-A:Data -> @r:Runner<A> -> Pair(Runner<A>, Bool)

The runner back, and whether no ticket is pending or running and no attempt runs.

def drain.handled source · line 1688 · raw

@-A:Data -> @t:Pair(Runner<A>, Out(Bool)) -> @next:(@_:Runner<A> -> IO(Ran(A))) -> IO(Ran(A))

def drain.ms source · line 1711 · raw

@-A:Data -> @idle:U32 -> @now:Nat -> @m:Maybe<&2, 0x77b88a2c45e79ff162b14cf8d6ee4112/queue.Ticket<A>> -> U32

ms to wait: idle, or less when the earliest pending ticket falls due sooner.

def soonest source · line 1718 · raw

@-A:Data -> @s:State<A> -> Maybe<&2, 0x77b88a2c45e79ff162b14cf8d6ee4112/queue.Ticket<A>>

def drain.end source · line 1761 · raw

@-A:Data -> @x:Pair(Runner<A>, Bool) -> Ran(A)

def orphans.next source · line 1775 · raw

@-A:Data -> @y:Ran(A) -> @err:Out(Unit) -> @next:(@_:Runner<A> -> @_:Out(Unit) -> IO(Ran(A))) -> IO(Ran(A))

def close.answer source · line 1789 · raw

@-A:Data -> @m:Msg<A> -> IO(Unit)

def close.polled source · line 1802 · raw

@-A:Data -> @x:Poll<&1, &1, Maybe<&1, Msg<A>>, Unit> -> @next:(@_:Unit -> IO(Unit)) -> IO(Unit)

def close.drain source · line 1814 · raw

@-A:Data -> @fuel:Nat -> @+ib:Chan(Msg<A>) -> IO(Unit)

Answers each ask left in the closed inbox with a failure. fuel bounds the messages it reads.

def close source · line 1824 · raw

@-A:Data -> @r:Runner<A> -> IO(Unit)

Closes the inbox and the journal. Each ask still in the inbox gets a failure, and no op is appended for it.

def open.done source · line 1831 · raw

@-A:Data -> @y:Ran(A) -> IO(Out(Runner<A>))

def state source · line 1868 · raw

@-A:Data -> @r:Runner<A> -> Pair(Runner<A>, State<A>)

The runner back, and a copy of its state.

Templates

template dead.get source · line 93 · raw

@-A:Data -> @ds:Graves(A) -> @+i:Nat -> Maybe<&2, Dead<A>>

template dead.drop source · line 96 · raw

@-A:Data -> @ds:Graves(A) -> @+i:Nat -> Graves(A)

template dead.bury source · line 99 · raw

@-A:Data -> @m:Maybe<&2, 0x77b88a2c45e79ff162b14cf8d6ee4112/queue.Ticket<A>> -> @ds:Graves(A) -> @w:Why -> @+at:Nat -> Graves(A)

template dead.drops source · line 141 · raw

@-A:Data -> @ks:List<&2, Nat> -> @ds:Graves(A) -> Graves(A)

template dead.purge source · line 149 · raw

@-A:Data -> @+ds:Graves(A) -> @+t:Nat -> Graves(A)

The dead tickets without those abandoned before t. It walks every dead ticket once.

template step.abandoned source · line 250 · raw

@-A:Data -> @r:Pair(0x77b88a2c45e79ff162b14cf8d6ee4112/queue.State<A>, Maybe<&2, 0x77b88a2c45e79ff162b14cf8d6ee4112/queue.Ticket<A>>) -> @ts:Tries -> @ds:Graves(A) -> @bs:Breakers -> @w:Why -> @+at:Nat -> State<A>

Abandon takes the ticket from the running list, as Complete does, and keeps it with its payload.

template step.revived source · line 255 · raw

@-A:Data -> @m:Maybe<&2, Dead<A>> -> @+i:Nat -> @n:Nat -> @h:0x55289dd95dde91bbc62b3e414066cf83/heap.Heap<0x77b88a2c45e79ff162b14cf8d6ee4112/queue.Ticket<A>> -> @r:List<&2, 0x77b88a2c45e79ff162b14cf8d6ee4112/queue.Ticket<A>> -> @ts:Tries -> @ds:Graves(A) -> @bs:Breakers -> @+d:Nat -> State<A>

The revived ticket keeps its payload and takes id i, the key it was dead under.

template step source · line 271 · raw

@-A:Data -> @s:State<A> -> @op:Op<A> -> State<A>

The state after op. Live and replay both run it, so they agree.

template apply.op source · line 296 · raw

@-A:Data -> @m:Maybe<&2, Op<A>> -> @s:State<A> -> Maybe<&2, State<A>>

template apply source · line 304 · raw

@-A:Data -> @-R:Type -> @-dec:(@_:R -> Maybe<&2, Op<A>>) -> @acc:Maybe<&2, State<A>> -> @r:R -> Maybe<&2, State<A>>

Folds one record into the replayed state. A record that does not decode ends the replay with None.

template load.rec source · line 316 · raw

@-A:Data -> @m:Maybe<&2, Rec<A>> -> @s:State<A> -> Maybe<&2, State<A>>

template load source · line 327 · raw

@-A:Data -> @-R:Type -> @-dec:(@_:R -> Maybe<&2, Rec<A>>) -> @acc:Maybe<&2, State<A>> -> @r:R -> Maybe<&2, State<A>>

Folds one record into the replayed state: a Snap replaces it, and an op steps it, as apply does. A record that does not decode ends the replay with None.

template pick source · line 360 · raw

@-A:Data -> @p:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Pool -> @s:State<A> -> @now:Nat -> Pick<A>

The ticket that Select{now} takes, with one unit of p, when there is a ticket due and a unit free.

template encode source · line 508 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @op:Op<A> -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes

template snap.ticket source · line 567 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @out:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> @t:0x77b88a2c45e79ff162b14cf8d6ee4112/queue.Ticket<A> -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes

template snap.heap source · line 571 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @h:0x55289dd95dde91bbc62b3e414066cf83/heap.Heap<0x77b88a2c45e79ff162b14cf8d6ee4112/queue.Ticket<A>> -> @out:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes

template snap.run source · line 578 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @xs:List<&2, 0x77b88a2c45e79ff162b14cf8d6ee4112/queue.Ticket<A>> -> @out:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes

template snap.entries source · line 592 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @es:List<&2, 0x55289dd95dde91bbc62b3e414066cf83/hmap.Entry<Nat, Dead<A>>> -> @out:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes

template snap.graves source · line 599 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @ds:Graves(A) -> @out:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes

template encode.snap source · line 616 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @s:State<A> -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes

The Snap record of s.

template encode.rec source · line 621 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @r:Rec<A> -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes

template rd.ticket source · line 712 · raw

@-A:Data -> @-pdec:(@_:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Maybe<&2, A>) -> Dec(0x77b88a2c45e79ff162b14cf8d6ee4112/queue.Ticket<A>)

template rd.heap source · line 721 · raw

@-A:Data -> @-pdec:(@_:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Maybe<&2, A>) -> @+fuel:Nat -> @node:Bool -> Dec(0x55289dd95dde91bbc62b3e414066cf83/heap.Heap<0x77b88a2c45e79ff162b14cf8d6ee4112/queue.Ticket<A>>)

Each rd.* tree reader takes the flag already read. fuel bounds the depth: every node holds at least one 4-octet flag.

template rd.run source · line 737 · raw

@-A:Data -> @-pdec:(@_:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Maybe<&2, A>) -> @+fuel:Nat -> @more:Bool -> Dec(List<&2, 0x77b88a2c45e79ff162b14cf8d6ee4112/queue.Ticket<A>>)

template rd.entries source · line 774 · raw

@-A:Data -> @-pdec:(@_:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Maybe<&2, A>) -> @+fuel:Nat -> @more:Bool -> Dec(List<&2, 0x55289dd95dde91bbc62b3e414066cf83/hmap.Entry<Nat, Dead<A>>>)

template rd.entry.le source · line 791 · raw

@-A:Data -> @a:0x55289dd95dde91bbc62b3e414066cf83/hmap.Entry<Nat, Dead<A>> -> @b:0x55289dd95dde91bbc62b3e414066cf83/hmap.Entry<Nat, Dead<A>> -> Bool

template rd.ascending source · line 796 · raw

@-A:Data -> @xs:List<&2, 0x55289dd95dde91bbc62b3e414066cf83/hmap.Entry<Nat, Dead<A>>> -> @+previous:Nat -> Bool

template rd.distinct source · line 803 · raw

@-A:Data -> @xs:List<&2, 0x55289dd95dde91bbc62b3e414066cf83/hmap.Entry<Nat, Dead<A>>> -> Bool

template rd.valid.go source · line 810 · raw

@-A:Data -> @+n:Nat -> @ds:Graves(A) -> Bool

template rd.valid source · line 829 · raw

@-A:Data -> @ds:Graves(A) -> Bool

template rd.graves source · line 833 · raw

@-A:Data -> @-pdec:(@_:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Maybe<&2, A>) -> @+fuel:Nat -> @nil:Bool -> @leaf:Bool -> @branch:Bool -> Dec(Graves(A))

A trie node whose kind is already read: nil is kind 0, leaf kind 1, and branch kind 2. Any other kind fails.

template rd.state source · line 928 · raw

@-A:Data -> @-pdec:(@_:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Maybe<&2, A>) -> @+fuel:Nat -> Dec(State<A>)

template decode.c source · line 996 · raw

@-A:Data -> @-pdec:(@_:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Maybe<&2, A>) -> @+tag:U32 -> @+len:U32 -> @+a:Nat -> @r:Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, Nat) -> Maybe<&2, Op<A>>

An Abandon is 28 octets; every other op without a payload is 20.

template decode.kind source · line 1000 · raw

@-A:Data -> @-pdec:(@_:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Maybe<&2, A>) -> @enq:Bool -> @+tag:U32 -> @+len:U32 -> @+a:Nat -> @b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Maybe<&2, Op<A>>

template decode.a source · line 1007 · raw

@-A:Data -> @-pdec:(@_:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Maybe<&2, A>) -> @+tag:U32 -> @+len:U32 -> @r:Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, Nat) -> Maybe<&2, Op<A>>

template decode.tag.if source · line 1011 · raw

@-A:Data -> @-pdec:(@_:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Maybe<&2, A>) -> @brk:Bool -> @+tag:U32 -> @+len:U32 -> @b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Maybe<&2, Op<A>>

template decode.tag source · line 1018 · raw

@-A:Data -> @-pdec:(@_:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Maybe<&2, A>) -> @+len:U32 -> @r:Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, U32) -> Maybe<&2, Op<A>>

template decode.len source · line 1022 · raw

@-A:Data -> @-pdec:(@_:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Maybe<&2, A>) -> @ok:Bool -> @+len:U32 -> @b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Maybe<&2, Op<A>>

template decode source · line 1030 · raw

@-A:Data -> @-pdec:(@_:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Maybe<&2, A>) -> @b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Maybe<&2, Op<A>>

The op of a record, or None when it is not one that encode writes.

template decode.snap source · line 1035 · raw

@-A:Data -> @-pdec:(@_:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Maybe<&2, A>) -> @b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Maybe<&2, State<A>>

The state of a Snap record whose tag is already checked. The decoder must end at the record's end.

template decode.rec.if source · line 1053 · raw

@-A:Data -> @-pdec:(@_:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Maybe<&2, A>) -> @snap:Bool -> @b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Maybe<&2, Rec<A>>

template decode.rec.tag source · line 1060 · raw

@-A:Data -> @-pdec:(@_:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Maybe<&2, A>) -> @r:Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, U32) -> Maybe<&2, Rec<A>>

template decode.rec source · line 1065 · raw

@-A:Data -> @-pdec:(@_:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Maybe<&2, A>) -> @b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Maybe<&2, Rec<A>>

The Rec of a journal record, or None when it is neither a Snap nor an op that encode.rec writes.

template commit.done source · line 1136 · raw

@-A:Data -> @x:Pair(Log, Out(Unit)) -> @s:State<A> -> @+op:Op<A> -> @p:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Pool -> @c:Config -> @ib:Chan(Msg<A>) -> @fs:List<&1, Flight<A>> -> Ran(A)

template commit source · line 1145 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @r:Runner<A> -> @+op:Op<A> -> IO(Ran(A))

Appends op, and applies it once the append is durable. After a failed append the state is as it was, and the journal refuses every later append until the runner is reopened.

template enqueue source · line 1159 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @r:Runner<A> -> @+deadline:Nat -> @x:A -> IO(Pair(Runner<A>, Out(Nat)))

Adds a job that is due at deadline (wall-clock ms) and answers its ticket id once the record is durable.

template cancel source · line 1166 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @r:Runner<A> -> @+id:Nat -> IO(Ran(A))

Cancels ticket id. A running attempt finishes, but its ticket is never selected again. A dead ticket is dropped.

template revive source · line 1171 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @r:Runner<A> -> @+id:Nat -> @+deadline:Nat -> IO(Ran(A))

Makes dead ticket id pending again at deadline (wall-clock ms), with its payload and a new retry budget. A ticket that is not dead does not change.

template purge source · line 1175 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @r:Runner<A> -> @+before:Nat -> IO(Ran(A))

Drops, as one record, the dead tickets that retry gave up on before before (wall-clock ms).

template purge.all source · line 1179 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @r:Runner<A> -> IO(Ran(A))

Drops every dead ticket, as one record.

template trip.if source · line 1245 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @same:Bool -> @r:Runner<A> -> @+key:String -> @st:0x14e48621ef66156b0eb652524b8594d4/retry.State -> IO(Ran(A))

template trip source · line 1253 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @r:Runner<A> -> @+key:String -> @+old:0x14e48621ef66156b0eb652524b8594d4/retry.State -> @br:0x14e48621ef66156b0eb652524b8594d4/retry.Breaker -> IO(Ran(A))

Appends a Break when the target's breaker left old, so that a reopen restores it.

template claim.go source · line 1257 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @-work:(@_:A -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)) -> @+now:Nat -> @gate:0x14e48621ef66156b0eb652524b8594d4/retry.Gate -> @+br:0x14e48621ef66156b0eb652524b8594d4/retry.Breaker -> @b:0x14e48621ef66156b0eb652524b8594d4/retry.Budget -> @+key:String -> @r:Runner<A> -> @+id:Nat -> @d:Nat -> @+x:A -> @g:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> @next:(@_:Runner<A> -> IO(Claimed(A))) -> IO(Claimed(A))

template claim.tripped source · line 1270 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @-work:(@_:A -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)) -> @+now:Nat -> @y:Ran(A) -> @gate:0x14e48621ef66156b0eb652524b8594d4/retry.Gate -> @+br:0x14e48621ef66156b0eb652524b8594d4/retry.Breaker -> @b:0x14e48621ef66156b0eb652524b8594d4/retry.Budget -> @+key:String -> @+id:Nat -> @d:Nat -> @+x:A -> @g:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> @next:(@_:Runner<A> -> IO(Claimed(A))) -> IO(Claimed(A))

template claim.gate source · line 1279 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @-work:(@_:A -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)) -> @+now:Nat -> @a:Pair(0x14e48621ef66156b0eb652524b8594d4/retry.Breaker, Pair(0x14e48621ef66156b0eb652524b8594d4/retry.Budget, 0x14e48621ef66156b0eb652524b8594d4/retry.Gate)) -> @+key:String -> @+old:0x14e48621ef66156b0eb652524b8594d4/retry.State -> @r:Runner<A> -> @+id:Nat -> @d:Nat -> @+x:A -> @g:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> @next:(@_:Runner<A> -> IO(Claimed(A))) -> IO(Claimed(A))

A change to the breaker is durable before the attempt starts.

template claim.admit source · line 1287 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)) -> @+now:Nat -> @r:Runner<A> -> @t:0x77b88a2c45e79ff162b14cf8d6ee4112/queue.Ticket<A> -> @g:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> @next:(@_:Runner<A> -> IO(Claimed(A))) -> IO(Claimed(A))

The selected ticket asks its target's breaker and its own budget for an attempt.

template claim.selected source · line 1297 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)) -> @+now:Nat -> @y:Ran(A) -> @t:0x77b88a2c45e79ff162b14cf8d6ee4112/queue.Ticket<A> -> @g:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> @next:(@_:Runner<A> -> IO(Claimed(A))) -> IO(Claimed(A))

template claim.pick source · line 1305 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)) -> @+left:Nat -> @+now:Nat -> @k:Pick<A> -> @j:Log -> @s:State<A> -> @c:Config -> @ib:Chan(Msg<A>) -> @fs:List<&1, Flight<A>> -> @next:(@_:Runner<A> -> IO(Claimed(A))) -> IO(Claimed(A))

template claim source · line 1317 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)) -> @fuel:Nat -> @+now:Nat -> @r:Runner<A> -> IO(Claimed(A))

Starts an attempt for each due ticket while the pool has a free unit; each attempt sends its outcome on the inbox. fuel bounds the tickets taken, and the fuel left comes back.

template settle.br source · line 1330 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @+op:Op<A> -> @y:Ran(A) -> @g:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> @err:Out(Unit) -> @next:(@_:Runner<A> -> @_:Out(Unit) -> IO(Pair(Runner<A>, Out(Bool)))) -> IO(Pair(Runner<A>, Out(Bool)))

template settle.op source · line 1342 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @+o:0x14e48621ef66156b0eb652524b8594d4/retry.Outcome -> @b:0x14e48621ef66156b0eb652524b8594d4/retry.Budget -> @+id:Nat -> @+key:String -> @+now:Nat -> @+rnd:Nat -> @r:Runner<A> -> @g:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Grant -> @err:Out(Unit) -> @next:(@_:Runner<A> -> @_:Out(Unit) -> IO(Pair(Runner<A>, Out(Bool)))) -> IO(Pair(Runner<A>, Out(Bool)))

Tells the target's breaker, appends the outcome's op, and returns the attempt's unit to the pool. The op of a cancelled ticket changes no state: the queue no longer holds it.

template settle.flight source · line 1382 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @mf:Maybe<&1, Flight<A>> -> @+o:0x14e48621ef66156b0eb652524b8594d4/retry.Outcome -> @+now:Nat -> @+rnd:Nat -> @r:Runner<A> -> @err:Out(Unit) -> @next:(@_:Runner<A> -> @_:Out(Unit) -> IO(Pair(Runner<A>, Out(Bool)))) -> IO(Pair(Runner<A>, Out(Bool)))

template settle.take source · line 1390 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @t:Pair(Maybe<&1, Flight<A>>, List<&1, Flight<A>>) -> @+o:0x14e48621ef66156b0eb652524b8594d4/retry.Outcome -> @+now:Nat -> @+rnd:Nat -> @j:Log -> @s:State<A> -> @p:0x8ef64648a1ae4481382be5e5ce2a9fc8/resources.Pool -> @c:Config -> @ib:Chan(Msg<A>) -> @err:Out(Unit) -> @next:(@_:Runner<A> -> @_:Out(Unit) -> IO(Pair(Runner<A>, Out(Bool)))) -> IO(Pair(Runner<A>, Out(Bool)))

template settle source · line 1397 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @+id:Nat -> @+o:0x14e48621ef66156b0eb652524b8594d4/retry.Outcome -> @+now:Nat -> @+rnd:Nat -> @r:Runner<A> -> @err:Out(Unit) -> @next:(@_:Runner<A> -> @_:Out(Unit) -> IO(Pair(Runner<A>, Out(Bool)))) -> IO(Pair(Runner<A>, Out(Bool)))

Settles the flight of ticket id with outcome o.

template handle source · line 1435 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @m:Msg<A> -> @+now:Nat -> @+rnd:Nat -> @r:Runner<A> -> @err:Out(Unit) -> @next:(@_:Runner<A> -> @_:Nat -> @_:Out(Unit) -> IO(Pair(Runner<A>, Out(Bool)))) -> IO(Pair(Runner<A>, Out(Bool)))

Settles an ended attempt, or appends an ask's op and answers it. next gets the claim fuel the message adds: 1 for an enqueue.

template compact.if source · line 1550 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @ok:Bool -> @j:0x67e4e1344805cb419bb08fd62348d5e5/journal.Journal -> @+max:U32 -> @+path:String -> @+limit:U32 -> @+base:U32 -> @s:State<A> -> IO(Pair(Log, Out(Unit)))

template compact source · line 1566 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @r:Runner<A> -> IO(Ran(A))

Writes the state as one Snap record into a new journal, fsyncs it, and renames it over the old one. A crash leaves one of the two journals, and both replay to this state. After a failure the old journal stands; when the failure came after the rename, appends stop until the runner is reopened.

template tick.due source · line 1584 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @due:Bool -> @+b:Bool -> @r:Runner<A> -> IO(Pair(Runner<A>, Out(Bool)))

template tick.size source · line 1593 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @r:Runner<A> -> @+b:Bool -> IO(Pair(Runner<A>, Out(Bool)))

template tick.grown source · line 1600 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @t:Pair(Runner<A>, Out(Bool)) -> IO(Pair(Runner<A>, Out(Bool)))

Compacts once the journal grew past Config.compact octets since open or the last compaction.

template tick.got source · line 1633 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)) -> @x:Pair(Runner<A>, Maybe<&1, Msg<A>>) -> @+ran:Bool -> @+left:Nat -> @err:Out(Unit) -> @next:(@_:Claimed(A) -> IO(Pair(Runner<A>, Out(Bool)))) -> IO(Pair(Runner<A>, Out(Bool)))

Handles the message, then claims due tickets into free units with the claim fuel left. None ends the round.

template tick.run source · line 1648 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)) -> @fuel:Nat -> @+ran:Bool -> @k:Claimed(A) -> IO(Pair(Runner<A>, Out(Bool)))

Handles messages until no attempt runs and the inbox is empty. fuel bounds the messages; attempts that still run when it ends stay in the runner, and the next tick settles them.

template tick.at source · line 1661 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)) -> @+now:Nat -> @r:Runner<A> -> IO(Pair(Runner<A>, Out(Bool)))

Fuel for each pending ticket, each attempt that may already run, and the last look at the inbox.

template tick source · line 1672 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)) -> @r:Runner<A> -> IO(Pair(Runner<A>, Out(Bool)))

One round: start an attempt for each due ticket the pool admits. Then read the inbox: as each attempt finishes, record its outcome, return its unit, and start the next due ticket in that unit; append and answer each ask from another fiber. The round ends when no attempt runs and the inbox is empty. Then compact the journal when it grew past Config.compact. Done{True} when an attempt ran or an ask was answered. work runs on its own; target names the breaker that guards it.

template drain.woke source · line 1695 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)) -> @+idle:U32 -> @x:Poll<&1, &1, Maybe<&1, Msg<A>>, Unit> -> @r:Runner<A> -> @next:(@_:Runner<A> -> IO(Ran(A))) -> IO(Ran(A))

template drain.poll source · line 1722 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)) -> @+ms:U32 -> @r:Runner<A> -> @next:(@_:Runner<A> -> IO(Ran(A))) -> IO(Ran(A))

template drain.wait source · line 1729 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)) -> @+idle:U32 -> @r:Runner<A> -> @next:(@_:Runner<A> -> IO(Ran(A))) -> IO(Ran(A))

template drain.ticked source · line 1736 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)) -> @+idle:U32 -> @t:Pair(Runner<A>, Out(Bool)) -> @next:(@_:Runner<A> -> IO(Ran(A))) -> IO(Ran(A))

template drain.if source · line 1746 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)) -> @done:Bool -> @r:Runner<A> -> @next:(@_:Runner<A> -> IO(Ran(A))) -> IO(Ran(A))

template drain.at source · line 1757 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)) -> @x:Pair(Runner<A>, Bool) -> @next:(@_:Runner<A> -> IO(Ran(A))) -> IO(Ran(A))

template drain source · line 1768 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @-target:(@_:A -> String) -> @-work:(@_:A -> IO(0x14e48621ef66156b0eb652524b8594d4/retry.Outcome)) -> @fuel:Nat -> @r:Runner<A> -> IO(Ran(A))

Ticks until no ticket is pending or running and no attempt runs. After a round that did nothing, it waits for a message up to idle ms, or until the earliest pending ticket is due when that is sooner, and handles one that arrives at once. Fails when fuel rounds leave work.

template orphans source · line 1780 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @ts:List<&2, 0x77b88a2c45e79ff162b14cf8d6ee4112/queue.Ticket<A>> -> @+now:Nat -> @r:Runner<A> -> @err:Out(Unit) -> IO(Ran(A))

A running ticket at open lost its attempt in a crash: it is requeued at now, as a failed attempt.

template open.got source · line 1840 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @x:Out(Pair(0x67e4e1344805cb419bb08fd62348d5e5/journal.Journal, Maybe<&2, State<A>>)) -> @+max:U32 -> @path:String -> @+limit:U32 -> @c:Config -> @+capacity:Nat -> IO(Out(Runner<A>))

template replay.step source · line 1856 · raw

@-A:Data -> @-pdec:(@_:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Maybe<&2, A>) -> @acc:Maybe<&2, State<A>> -> @b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Maybe<&2, State<A>>

template open source · line 1862 · raw

@-A:Data -> @-penc:(@_:A -> 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> @-pdec:(@_:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> Maybe<&2, A>) -> @+path:String -> @+max:U32 -> @+limit:U32 -> @c:Config -> @+capacity:Nat -> IO(Out(Runner<A>))

Opens the runner at path: replays its journal into the state, then requeues each ticket that was running. capacity bounds the attempts that run at once. max caps an op record's octets; limit caps the journal file and a snapshot. Fails when the journal fails to open, or a committed record is not a snapshot or an op.