ela
Contents

ManualAgents

Time limits: with time.block and time.each

In the terminalela --spec time-limits-with-time-block-and-time-each

with time.block bounds a wait. Every line of its block ends within the limit, its loops and jobs included.

ela <<'EOF'proc fetch_all(repos: list)    with time.block = "2m"        for r in $repos            git -C $r fetch        end for    end withend proc err = try fetch_all(["api", "web"])if error.is($err, Error.TIMEOUT)    echo "the fetch took too long: $err"end ifEOF
  • Past the limit, the script stops at the with line, names the line that was running and exits 124.
  • try on a proc that holds the block gives an Error of kind Error.TIMEOUT instead, and the script goes on.
  • with time.each = "30s" gives each command of the block its own limit. One past it is ended and exits 124, which try on it gives as an Error.TIMEOUT, and the block goes on. One command alone is the one-line form, ela's own for timeout 20 git status:
with time.each = "20s"; out, err = try $(git status)if error.is($err, Error.TIMEOUT)    echo "git status did not answer in 20s"end if

(ela --spec time-block-and-time-each)