This file contains hidden or 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
var cluster = require('cluster'); | |
var PORT = +process.env.PORT || 1337; | |
if (cluster.isMaster) { | |
// In real life, you'd probably use more than just 2 workers, | |
// and perhaps not put the master and worker in the same file. | |
cluster.fork(); | |
cluster.fork(); | |
cluster.on('disconnect', function(worker) { |
This file contains hidden or 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
function apiMergeCall(apis, mainid, timeout, callback){ | |
var api_count = apis.length, ready_count = 0, rst = {}, is_ret = false, start_time = new Date().getTime(), | |
doCallback = function(){ | |
if (!is_ret && (is_ret = true)) { | |
timer && clearTimeout(timer); | |
callback(rst); | |
} | |
}, | |
chkResult = function(id, ret){ | |
rst[id] = ret; |
This file contains hidden or 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
var callA = function (callback) { | |
setTimeout(function () { | |
callback({name: "a", data: "I am result A"}); | |
}, Math.round(Math.random() * 300)); | |
}; | |
var callB = function (callback) { | |
setTimeout(function () { | |
callback({name: "b", data: Math.round(Math.random() * 300)) % 2 === 0}); | |
}, Math.round(Math.random() * 300)); |
This file contains hidden or 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
// http://mongoosejs.com/docs/virtuals.html | |
// npm install mongoose underscore | |
var _ = require('underscore'); | |
var mongoose = require('mongoose'); | |
mongoose.connect(process.env.MONGOLAB_URI || process.env.MONGOHQ_URL || 'mongodb://localhost/test', function(err){ | |
if(err){ | |
console.error(err); | |
process.exit(1); |
This file contains hidden or 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
var emitter = new event.Emitter(); | |
var status = "ready"; | |
var select = function (callback) { | |
emitter.once("selected", function (results) { | |
callback(results); | |
}); | |
if (status === "ready") { | |
status = "pending"; | |
db.select("SQL", function (results) { |
This file contains hidden or 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
var assert = require('assert'); | |
var net = require('net'); | |
var open = process.binding('fs').open; | |
var sendfile = process.binding('fs').sendfile; | |
if (process.argv.length < 4) { | |
console.error('usage: sendfile <port> <path>'); | |
process.exit(1); | |
} |