mirror of
https://github.com/Fabio286/antares.git
synced 2025-02-22 22:47:44 +01:00
refactor: improvements in worker implementation
This commit is contained in:
parent
c176841b75
commit
45a695ac0a
@ -63,43 +63,39 @@ async function restartElectron () {
|
|||||||
if (!manualRestart) process.exit(0);
|
if (!manualRestart) process.exit(0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
function startWorkers () {
|
||||||
function startMain () {
|
const compiler = webpack(workersConfig);
|
||||||
const webpackSetup = webpack([mainConfig, workersConfig]);
|
|
||||||
|
|
||||||
webpackSetup.compilers.forEach((compiler) => {
|
|
||||||
const { name } = compiler;
|
const { name } = compiler;
|
||||||
|
|
||||||
switch (name) {
|
compiler.hooks.afterEmit.tap('afterEmit', () => {
|
||||||
case 'workers':
|
|
||||||
compiler.hooks.afterEmit.tap('afterEmit', async () => {
|
|
||||||
console.log(chalk.gray(`\nCompiled ${name} script!`));
|
console.log(chalk.gray(`\nCompiled ${name} script!`));
|
||||||
console.log(
|
console.log(chalk.gray(`\nWatching file changes for ${name} script...`));
|
||||||
chalk.gray(`\nWatching file changes for ${name} script...`)
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
break;
|
|
||||||
case 'main':
|
compiler.watch({ aggregateTimeout: 500 }, err => {
|
||||||
default:
|
if (err) console.error(chalk.red(err));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function startMain () {
|
||||||
|
const compiler = webpack(mainConfig);
|
||||||
|
const { name } = compiler;
|
||||||
|
|
||||||
compiler.hooks.afterEmit.tap('afterEmit', async () => {
|
compiler.hooks.afterEmit.tap('afterEmit', async () => {
|
||||||
console.log(chalk.gray(`\nCompiled ${name} script!`));
|
console.log(chalk.gray(`\nCompiled ${name} script!`));
|
||||||
|
|
||||||
manualRestart = true;
|
manualRestart = true;
|
||||||
await restartElectron();
|
await restartElectron();
|
||||||
|
startWorkers();
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
manualRestart = false;
|
manualRestart = false;
|
||||||
}, 2500);
|
}, 2500);
|
||||||
|
|
||||||
console.log(
|
console.log(chalk.gray(`\nWatching file changes for ${name} script...`));
|
||||||
chalk.gray(`\nWatching file changes for ${name} script...`)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
webpackSetup.watch({ aggregateTimeout: 500 }, err => {
|
compiler.watch({ aggregateTimeout: 500 }, err => {
|
||||||
if (err) console.error(chalk.red(err));
|
if (err) console.error(chalk.red(err));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -235,7 +235,9 @@ export default (connections: {[key: string]: antares.Client}) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Init exporter thread
|
// Init exporter thread
|
||||||
exporter = new Worker(isDevelopment ? './dist/exporter.js' : './exporter.js');
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
// @ts-ignore
|
||||||
|
exporter = new Worker(new URL('../workers/exporter', import.meta.url));
|
||||||
|
|
||||||
exporter.postMessage({
|
exporter.postMessage({
|
||||||
type: 'init',
|
type: 'init',
|
||||||
@ -255,18 +257,18 @@ export default (connections: {[key: string]: antares.Client}) => {
|
|||||||
break;
|
break;
|
||||||
case 'end':
|
case 'end':
|
||||||
setTimeout(() => { // Ensures that writing thread has finished
|
setTimeout(() => { // Ensures that writing thread has finished
|
||||||
exporter.terminate();
|
exporter?.terminate();
|
||||||
exporter = null;
|
exporter = null;
|
||||||
}, 2000);
|
}, 2000);
|
||||||
resolve({ status: 'success', response: payload });
|
resolve({ status: 'success', response: payload });
|
||||||
break;
|
break;
|
||||||
case 'cancel':
|
case 'cancel':
|
||||||
exporter.terminate();
|
exporter?.terminate();
|
||||||
exporter = null;
|
exporter = null;
|
||||||
resolve({ status: 'error', response: 'Operation cancelled' });
|
resolve({ status: 'error', response: 'Operation cancelled' });
|
||||||
break;
|
break;
|
||||||
case 'error':
|
case 'error':
|
||||||
exporter.terminate();
|
exporter?.terminate();
|
||||||
exporter = null;
|
exporter = null;
|
||||||
resolve({ status: 'error', response: payload });
|
resolve({ status: 'error', response: payload });
|
||||||
break;
|
break;
|
||||||
|
@ -19,7 +19,15 @@ module.exports = { // Main
|
|||||||
output: {
|
output: {
|
||||||
libraryTarget: 'commonjs2',
|
libraryTarget: 'commonjs2',
|
||||||
path: path.join(__dirname, 'dist'),
|
path: path.join(__dirname, 'dist'),
|
||||||
filename: '[name].js'
|
filename: '[name].js',
|
||||||
|
assetModuleFilename: (pathData) => {
|
||||||
|
const { filename } = pathData;
|
||||||
|
|
||||||
|
if (filename.endsWith('.ts'))
|
||||||
|
return '[name].js';
|
||||||
|
else
|
||||||
|
return '[name][ext]';
|
||||||
|
}
|
||||||
},
|
},
|
||||||
node: {
|
node: {
|
||||||
global: true,
|
global: true,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user