aboutsummaryrefslogtreecommitdiff
path: root/bench/snippets/rmdir.mjs
blob: 258d69097d483c941d40b3caea55d7fb28ebf3ad (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { tmpdir } from "node:os";
import { promises, existsSync, mkdirSync } from "node:fs";
const count = 1024 * 12;

var queue = new Array(count);
var paths = new Array(count);
for (let i = 0; i < count; i++) {
  const path = `${tmpdir()}/${Date.now()}.rm.dir${i}`;
  try {
    mkdirSync(path);
  } catch (e) {}
  paths[i] = path;
  queue[i] = promises.rmdir(path);
}

await Promise.all(queue);

for (let i = 0; i < count; i++) {
  if (existsSync(paths[i])) {
    throw new Error(`Path ${paths[i]} was not removed`);
  }
}