libs/server.js
function (i) {
                    workers[i] = cluster.fork();

                    console.log('Creating Worker: ', workers[i].process.pid);
                    workers[i].on('message', m => {
                        switch (m.type) {
                            case 'STARTED':
                                !startedWorkers && startWatches();
                                break;
                        }
                    });
                    // Optional: Restart worker on exit
                    workers[i].on('exit', function (code, signal) {
                        console.log('Respawning worker', i);
                        spawn(i);
                    });
                }
function (i) {
                    workers[i] = cluster.fork();

                    console.log('Creating Worker: ', workers[i].process.pid);
                    workers[i].on('message', m => {
                        switch (m.type) {
                            case 'STARTED':
                                !startedWorkers && startWatches();
                                break;
                        }
                    });
                    // Optional: Restart worker on exit
                    workers[i].on('exit', function (code, signal) {
                        console.log('Respawning worker', i);
                        spawn(i);
                    });
                }
function ( i ) { workers [ i ] = cluster . fork ( ) ; console . log ( 'Creating Worker: ' , workers [ i ] . process . pid ) ; workers [ i ] . on ( 'message' , m => { switch ( m . type ) { case 'STARTED' : ! startedWorkers && startWatches ( ) ; break ; } } ) ; // Optional: Restart worker on exit workers [ i ] . on ( 'exit' , function ( code , signal ) { console . log ( 'Respawning worker' , i ) ; spawn ( i ) ; } ) ; }
This stores our workers. We need to keep them to be able to reference them based on source IP address. It's also useful for auto-restart, for example.
This stores our workers . We need to keep them to be able to reference them based on source IP address . It s also useful for auto - restart for example .