Skip to content

Instantly share code, notes, and snippets.

@yourtion
Created February 2, 2018 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yourtion/6d2f0c06e0879bc5c525b09b2c0a20bd to your computer and use it in GitHub Desktop.
Save yourtion/6d2f0c06e0879bc5c525b09b2c0a20bd to your computer and use it in GitHub Desktop.
Node.js Simple IPC Timmer Demo
const { fork } = require('child_process');
const crypto = require('crypto');
const timmer = fork('./timmer.js');
let lastTime = Date.now();
let localTime = Date.now();
timmer.on('message', (m) => {
console.log('remote: ', m.time - lastTime - 1000 + 'ms');
const now = Date.now();
console.log('local: ', now - localTime - 1000 + 'ms');
lastTime = m.time;
localTime = now;
});
function loop() {
setTimeout(() => {
loop()
crypto.getDiffieHellman('modp14');
crypto.getDiffieHellman('modp14');
}, 1000);
}
loop();
const crypto = require('crypto');
let lastTime = Date.now();
setInterval(() => {
const now = Date.now()
console.log(now - lastTime - 1000 + 'ms');
lastTime = now;
crypto.getDiffieHellman('modp14');
crypto.getDiffieHellman('modp14');
}, 1000);
setInterval(() => {
process.send({ time: Date.now() });
}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment