@gigzen/populace 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/cli.mjs +35 -2
package/package.json
CHANGED
package/src/cli.mjs
CHANGED
|
@@ -301,10 +301,43 @@ async function run() {
|
|
|
301
301
|
},
|
|
302
302
|
});
|
|
303
303
|
|
|
304
|
-
|
|
304
|
+
const askedToStop = () => {
|
|
305
|
+
if (world.stopping) return;
|
|
305
306
|
world.stop();
|
|
306
307
|
console.log(`\n Stopping…\n`);
|
|
307
|
-
}
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
process.on("SIGINT", askedToStop);
|
|
311
|
+
|
|
312
|
+
/*
|
|
313
|
+
* A second way to ask, because the first one does not exist on Windows.
|
|
314
|
+
*
|
|
315
|
+
* `child.kill("SIGTERM")` there does not deliver a signal - Windows has no
|
|
316
|
+
* POSIX signals, so Node terminates the process outright whatever name is
|
|
317
|
+
* passed. A parent asking politely therefore killed the run mid-flight and
|
|
318
|
+
* stranded every account it had created, which is the one promise this tool
|
|
319
|
+
* makes loudest. Measured on 2026-08-26: pressing Stop during a 200-person
|
|
320
|
+
* run left all 200 behind.
|
|
321
|
+
*
|
|
322
|
+
* stdin works the same on every platform. A line containing "stop" asks for
|
|
323
|
+
* the same orderly wind-down SIGINT does: finish the tick, tear down, delete
|
|
324
|
+
* the accounts, write the report.
|
|
325
|
+
*
|
|
326
|
+
* unref() so simply having this listener never keeps the process alive, and
|
|
327
|
+
* resume() because a paused stdin emits nothing.
|
|
328
|
+
*/
|
|
329
|
+
if (!process.stdin.isTTY) {
|
|
330
|
+
let pending = "";
|
|
331
|
+
process.stdin.on("data", (chunk) => {
|
|
332
|
+
pending += String(chunk);
|
|
333
|
+
const lines = pending.split("\n");
|
|
334
|
+
pending = lines.pop() ?? "";
|
|
335
|
+
if (lines.some((l) => l.trim() === "stop")) askedToStop();
|
|
336
|
+
});
|
|
337
|
+
process.stdin.on("error", () => {}); // a closed pipe is not a reason to fail a run
|
|
338
|
+
process.stdin.resume();
|
|
339
|
+
process.stdin.unref();
|
|
340
|
+
}
|
|
308
341
|
|
|
309
342
|
await world.populate();
|
|
310
343
|
if (!world.agents.length) {
|