Skip to content

Schedules

A schedule answers one question: something changed, so what runs, and in which order? coeval keeps this question out of the meaning of a document. The meaning says what a value is. The schedule says when to compute it.

Schedule When it computes Where it fits
Pull When a reader asks for a value. A change only marks the readers as old. Signals in a browser
Push When a value changes. Its readers compute in the order of the graph, until the values stop changing. A reactive store with epochs
Demand When a cell is read, one time for each run, with a check for cycles A spreadsheet
Once One time, in the written order A server, or a command line

Three formula cards read the inputs a and b. Change a, then read a cell. Each column is one schedule. A lit cell computed in the last step, and a count shows how many times each cell computed.

a = 2, b = 3. The cells start with their values.

Push

A change computes each reader at once, in the order of the graph.

c
add
ref
namesa
ref
namesb
5×0
d
multiply
ref
namesc
number
2
10×0
e
multiply
ref
namesa
number
10
20×0

Computations: 0

Pull

A change marks the readers as old. A read computes what is old.

c
add
ref
namesa
ref
namesb
5×0
d
multiply
ref
namesc
number
2
10×0
e
multiply
ref
namesa
number
10
20×0

Computations: 0

Demand

Each read computes what it needs, one time for each cell.

c
add
ref
namesa
ref
namesb
5×0
d
multiply
ref
namesc
number
2
10×0
e
multiply
ref
namesa
number
10
20×0

Computations: 0

Once

Each read computes each cell again, as a page that a server renders.

c
add
ref
namesa
ref
namesb
5×0
d
multiply
ref
namesc
number
2
10×0
e
multiply
ref
namesa
number
10
20×0

Computations: 0

Select Change a, then Read d. Each schedule computes other cells at other times. A lit cell computed in the last step.

For the derive side, each schedule gives the same values. This is the benefit of pure work. Thus each host can choose its own schedule. A browser can pull, a store with epochs can push, and a server can compute a page once.

For the run side, the program itself gives the order. The schedule only starts the run on its trigger.

A schedule needs two things:

  • The graph of the data. Each kind declares what it reads, in its contract. From the contracts, a tool can make the graph of a document before it runs.
  • The side of each kind. A schedule can repeat derive work, and it must not repeat a run.

The diagram above gets its graph from the formulas: refsOf finds the names that each formula reads.

From the graph, a static analysis gives three results before the start. It finds the cycles, an order for a push schedule, and the independent groups of nodes. Independent groups can compute at the same time.

The functions cycles, heights and nodeLayers give these three results, and necessary gives the nodes that an observer needs (decision D33). A cycle of eager reads is certain. A cycle through a branch of if is only possible, because the test can skip the read. The demand still gives the value of each node. The function checkCycles gives each certain cycle as an issue with the code #CYCLE!, before a run (decision D131).

A push schedule can stop early. When a cell computes again and gives the same result as before, its readers do not compute again. This is an early cutoff.

The test of “the same result” must be safe for each value. sameResult compares plain JSON by structure, and each other object only as itself. Two errors are the same only with the same code, reason and place (decision D20).