UNPKG

sc4

Version:

A command line utility for automating SimCity 4 modding tasks & modifying savegames

19 lines (18 loc) 627 B
// # worker-thread.js import { isMainThread, parentPort } from 'node:worker_threads'; // Helper function for running code inside a worker thread that takes care of // the task ids automatically. It also ensures that we can run both in the main // thread, as in the worker thread. export default function workerThread(fn) { if (isMainThread) { return function (task) { return fn(task); }; } else { parentPort.on('message', async ({ id, task }) => { let result = await fn(task); parentPort.postMessage({ id, type: 'result', result }); }); } }