Lab
Pure functions
type Trial = { endsOn: number };
let serviceDay = 40;
const audit: string[] = [];
const readDay = () => serviceDay;
// #region core
function remainingAt(trial: Trial, today: number): number {
const daysLeft = Math.max(0, trial.endsOn - today);
return daysLeft;
}
// #endregion
function inspectTrial(trial: Trial): number {
const today = readDay();
const daysLeft = remainingAt(trial, today);
audit.push(`inspected:${daysLeft}`);
return daysLeft;
}
const trial: Trial = { endsOn: 43 };
const today = readDay();
const first = remainingAt(trial, today);
console.log(`first: ${first}`);
serviceDay = 41;
const second = remainingAt(trial, today);
console.log(`second: ${second}`);
console.log(`audit before shell: ${audit.length}`);
const inspected = inspectTrial(trial);
console.log(`shell: ${inspected}`);
console.log(`audit after shell: ${audit.length}`);
Time outside the calculation
The calendar can advance. A captured value stays put.
01First calculationWaiting for the call
·answer pending
02Repeat calculationWaiting for the call
·answer pending
An explicit inspection
This action has its own clock read and audit write.
Audit journal
Not read yetObserved local audit listThe caller has a trial to inspect. First, it needs a day to use.