Created
June 2, 2012 00:02
-
-
Save Raynos/2855863 to your computer and use it in GitHub Desktop.
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
var MC = require('emcee') | |
// add a bunch of models | |
MC.model('login', function (req, cb) { | |
// callback is called with (er, data) | |
req.session.get('login', cb) | |
}) | |
MC.model('train', function (url, res, cb) { | |
}) | |
// later on... | |
http.createServer(function (req, res) { | |
// check if the user is logged in. | |
var m = new MC() | |
m.load('login', req) | |
m.load('bike', req.url, res) | |
m.end(function (er, models) { | |
// either there is an error, or all models are loaded on the | |
// 'models' object. note that all errors are assumed to be | |
// catastrophic, so you only get the first error, and the | |
// models object will only contain the models that got loaded | |
// before the error occurred. | |
}) | |
}).listen(1337) |
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
var models = { | |
login: login, | |
train: train | |
} | |
function login(req, cb) { | |
req.session.get('login', cb) | |
} | |
function train(url, res, cb) { | |
... | |
} | |
http.createServer(function (req, res) { | |
flowControlMap({ | |
"login": [req] | |
"bike": [req.url, res] | |
}, iterator, function (er, models) { | |
// either there is an error, or all models are loaded on the | |
// 'models' object. note that all errors are assumed to be | |
// catastrophic, so you only get the first error, and the | |
// models object will only contain the models that got loaded | |
// before the error occurred. | |
}) | |
function iterator(value, name, callback) { | |
value.push(callback) | |
models[name].apply(models[name], value) | |
} | |
}).listen(1337) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment