mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 20:03:12 +03:00
23 lines
586 B
JavaScript
23 lines
586 B
JavaScript
const {isMainThread, parentPort, workerData} = require('bthreads');
|
|
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();
|
|
})();
|
|
}
|