Ghost/ghost/job-manager/test/jobs/timed-job.js
Daniel Lockyer c2e45b657f Removed bthreads dependency in favor of native worker_threads
fixes https://github.com/TryGhost/Toolbox/issues/370

- we no longer need `bthreads` because we can use native
  `worker_threads` now we don't have to support Node 10 any longer
- this allows us to clean up a dependency and stick with native
  libraries
- the referenced node-sqlite3 issue should be fixed (or at least, we now
  maintain it so we can fix it if not)
2022-08-09 09:04:59 +02:00

23 lines
592 B
JavaScript

const {isMainThread, parentPort, workerData} = require('worker_threads');
const util = require('util');
const setTimeoutPromise = util.promisify(setTimeout);
const passTime = async (ms) => {
if (Number.isInteger(ms)) {
await setTimeoutPromise(ms);
} else {
await setTimeoutPromise(ms.ms);
}
};
if (isMainThread) {
module.exports = passTime;
} else {
(async () => {
await passTime(workerData.ms);
parentPort.postMessage('done');
// alternative way to signal "finished" work (not recommended)
// process.exit();
})();
}