-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.ts
More file actions
28 lines (23 loc) · 731 Bytes
/
app.ts
File metadata and controls
28 lines (23 loc) · 731 Bytes
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
import * as fs from 'fs/promises';
import queue from './queue';
import { startProducers, stopProducers } from './producer';
import { startConsumer, Stats } from './consumer';
async function saveStats(timeSpent: number, numbersGenerated: Stats) {
await fs.appendFile(
'result.json',
JSON.stringify({ timeSpent, numbersGenerated }, null, 2),
{ flag: 'w' }
);
}
async function main() {
await queue.init();
const startAt = new Date();
const producers = startProducers();
const stats = await startConsumer();
stopProducers();
await producers;
queue.destroy();
const finishAt = new Date();
await saveStats(Number(finishAt) - Number(startAt), stats);
}
main();