Skip to content

Instantly share code, notes, and snippets.

$ coffee child_process_example.coffee
Launching child processes
Before fork
After fork
I am a child process
I am a child process
I am a child process
I am a child process
I am a child process
I am a child process
launcher = require('./child_process_launcher')
console.log 'Launching cluster'
launcher.launch()
child_process = require 'child_process'
numCPUs = require('os').cpus().length
exports = module.exports = launch: ->
console.log 'Before fork'
child_process.fork("#{__dirname}/another_process") for i in [0...numCPUs]
console.log 'After fork'
$ coffee cluster_example.coffee
Launching cluster
Before the fork
I am the master, launching workers!
After the fork
Launching cluster
Before the fork
I am a worker!
After the fork
Launching cluster
launcher = require('./cluster_launcher')
console.log 'Launching cluster'
launcher.launch()
cluster = require 'cluster'
numCPUs = require('os').cpus().length
exports = module.exports = launch: ->
console.log 'Before the fork'
if (cluster.isMaster)
console.log 'I am the master, launching workers!'
cluster.fork() for i in [0...numCPUs]
else
module.exports.setForegroundColor = (color)->
process.stdout.write "\x1b[3#{color}m"
module.exports.setBackgroundColor = (color)->
process.stdout.write "\x1b[4#{color}m"
module.exports.moveTo = (x, y) ->
{ x, y } = transform(x,y)
process.stdout.write "\x1b[#{y};#{x}f"
#!/usr/bin/env node
// vim:ft=js ts=2 sw=2 et :
// -*- mode:javascript -*-
var vimtronner = require('../lib/vimtronner');
vimtronner(process.argv);
{
"name": "vimtronner",
"version": "0.0.9",
"description": "A multi-player Vim trainer.",
"main": "lib/vimtronner.js",
...,
"dependencies": {
"socket.io": "",
"socket.io-client": "",
"commander": "",
onGameChange: (game)=>
@io.sockets.in(game.name).emit 'game', game.toJSON()