Open History to see the last commit
1/** Record a finite execution only after its driver enters a law comparison. */
2export async function withFiniteComparison(action, record) {
3 let compared = false
4 let failed = false
5 let primary
6 try {
7 return await action(() => {
8 compared = true
9 })
10 } catch (error) {
11 failed = true
12 primary = error
13 throw error
14 } finally {
15 if (compared) {
16 try {
17 record({ failed })
18 } catch (witness) {
19 throw failed
20 ? new AggregateError(
21 [primary, witness],
22 'Finite comparison and witness failures',
23 { cause: primary },
24 )
25 : witness
26 }
27 }
28 }
29}