src/ez/clock.bend

ezx@1.4.0.0 · 24 lines · 0 definitions

1# ez/clock: the wall-clock budget a run has to finish inside.
2#
3# `ez test` is held to it, since a check nobody waits for is not one. The
4# budget is a comparison like any other: it is checked, it is counted, and a run that
5# overran fails on it the way a test that printed the wrong line fails. That is
6# the difference between a number in a readme and a number something enforces.
7#
8# Base has no clock and no arithmetic over what `date` prints, and neither is
9# needed. `date -d` works out the deadline at the start, and `test -gt` does
10# the one comparison at the end, so nothing here parses a number. Both are
11# programs ez already runs the way it runs `find` and `mkdir`, with no shell
12# between, and running them is ez/timer's: this half holds what a law reads.
13import Base
14
15# whether a budget is being kept at all
16def on(+secs: String) -> Bool:
17  Bool.not(Bool.or(String.is_empty(secs), String.eq(secs, "0")))
18
19# the deadline as the run effect wants it: an absolute second, or "0" when
20# there is no budget to keep. The effect is what queues the jobs, so it is what
21# keeps the deadline; a job bounded by what was left when its batch started is
22# not bounded at all once it waits its turn behind three others.
23def by.effect(+deadline: String) -> String:
24  Bool.pick(String, String.is_empty(deadline), "0", deadline)