Advertisement
Guest User

Untitled

a guest
Apr 29th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. //forking a process using cluster
  2. var cluster = require('cluster');
  3. var http = require('http');
  4. var numCPUs = 4;
  5.  
  6. if (cluster.isMaster) {
  7. for (var i = 0; i < numCPUs; i++) {
  8. cluster.fork();
  9. }
  10. } else {
  11. http.createServer(function(req, res) {
  12. res.writeHead(200);
  13. res.end('process ' + process.pid + ' says hello!');
  14. }).listen(8000);
  15. }
  16.  
  17. 'use strict';
  18.  
  19. const electron = require('electron');
  20. const app = electron.app; // Module to control application life.
  21. const BrowserWindow = electron.BrowserWindow; // Module to create native browser window.
  22.  
  23. // Keep a global reference of the window object, if you don't, the window will
  24. // be closed automatically when the JavaScript object is garbage collected.
  25. var mainWindow = null;
  26.  
  27. // Quit when all windows are closed.
  28. app.on('window-all-closed', function() {
  29. // On OS X it is common for applications and their menu bar
  30. // to stay active until the user quits explicitly with Cmd + Q
  31. if (process.platform != 'darwin') {
  32. app.quit();
  33. }
  34. });
  35.  
  36. // This method will be called when Electron has finished
  37. // initialization and is ready to create browser windows.
  38. app.on('ready', function() {
  39. // Create the browser window.
  40. mainWindow = new BrowserWindow({width: 800, height: 600});
  41.  
  42. // and load the index.html of the app.
  43. mainWindow.loadURL('file://' + __dirname + '/index.html');
  44.  
  45. // Open the DevTools.
  46. mainWindow.webContents.openDevTools();
  47.  
  48. // Emitted when the window is closed.
  49. mainWindow.on('closed', function() {
  50. // Dereference the window object, usually you would store windows
  51. // in an array if your app supports multi windows, this is the time
  52. // when you should delete the corresponding element.
  53. mainWindow = null;
  54. });
  55. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement