Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

sqlite3 multithreading nodejs

const cluster = require('cluster');
const db = new sqlite3.Database(':memory:')

if (cluster.isMaster) {
    console.log(`Master ${process.pid} is running`);
    cluster.fork()
        .on('exit', (worker, code, signal) => {
            console.log(`worker ${worker.process.pid} died`);
        });
    cluster.fork()
        .on('exit', (worker, code, signal) => {
            console.log(`worker ${worker.process.pid} died`);
        });

} else if (cluster.worker.id === 1){
  db.run(QUERY1);
} else {
 db.run(QUERY2);
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #multithreading #nodejs
ADD COMMENT
Topic
Name
8+2 =