-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexecution-trace.ts
More file actions
35 lines (29 loc) · 1.05 KB
/
Copy pathexecution-trace.ts
File metadata and controls
35 lines (29 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* Execution example — one call, recorded.
*
* No engine, no graph, no wiring: `executionTrace` runs a single function and
* hands back what it did — the inputs it received, the value it returned, when
* it started and finished, and how long it took. The function itself is
* untouched and still returns its own value to its own caller.
*
* This is the smallest thing the library does, and the whole of part one.
*/
import { executionTrace } from '../src';
import { writeTrace } from './common/writeTrace';
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
interface Invoice {
id: string;
total: number;
currency: string;
}
/** Pretends to be a database round trip. */
async function fetchInvoice(id: string): Promise<Invoice> {
await sleep(45);
return { id, total: 128.4, currency: 'EUR' };
}
export async function run() {
const trace = await executionTrace(fetchInvoice, ['inv_204']);
console.log(`${trace.outputs.id} took ${trace.elapsedTime}`);
writeTrace(JSON.stringify(trace, null, 2));
}
run().then();