c2e45b657f
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)
23 lines
592 B
JavaScript
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();
|
|
})();
|
|
}
|