Skip to content

Instantly share code, notes, and snippets.

@qcom
Last active August 29, 2015 13:59
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 qcom/10676433 to your computer and use it in GitHub Desktop.
Save qcom/10676433 to your computer and use it in GitHub Desktop.
oh control flow I don't understand you
// app.get('db') is a reference to my wrapper module over knex.js
// which just bundles actions/behavior into entity-named properties (tag, jobIndustries, etc.)
app.get('db').tag.getBelongingToJob(job.job_id)
.then(function(tags) {
job.tags = tags;
return app.get('db').jobIndustries.get(job.job_industry);
}).then(function(jobIndustry) {
job.job_industry = jobIndustry;
return app.get('db').jobCategories.get(job.job_category);
}).then(function(jobCategory) {
job.job_category = jobCategory;
return app.get('db').company.get(job.company_id);
}).then(function(company) {
job.company = company;
req.job = job;
next();
});
@benjamingr
Copy link

var job = Promise.props({
    tags: pp.get('db').tag.getBelongingToJob(job.job_id),
    job_industry: app.get('db').jobIndustries.get(job.job_industry),
    job_category: app.get('db').jobCategories.get(job.job_category),
    company: app.get('db').company.get(job.company_id)
}).then(function(job){
    req.job = job;
    next();
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment