-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreadme.ts
More file actions
27 lines (23 loc) · 700 Bytes
/
readme.ts
File metadata and controls
27 lines (23 loc) · 700 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
import { unlink, writeFile } from "fs/promises";
import { addCleanupListener, exitAfterCleanup } from "../src";
void (async function () {
const path = ".lockfile";
try {
await writeFile(path, String(process.pid), { flag: "wx" });
} catch (err) {
if ((err as { code?: string }).code === "EEXIST") {
console.log(`${path} already exists`);
} else {
console.log(`Error writing ${path}`, err);
}
// Can't use process.exit with async cleanup
await exitAfterCleanup(1);
}
console.log(`Created ${path}`);
addCleanupListener(async () => {
await unlink(path);
console.log(`Deleted ${path}`);
});
// Do stuff...
console.log("Stuff done");
})();