Created
February 2, 2018 15:38
-
-
Save yourtion/6d2f0c06e0879bc5c525b09b2c0a20bd to your computer and use it in GitHub Desktop.
Node.js Simple IPC Timmer Demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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