Skip to content

Commit

Permalink
Refactor parallel post/user get.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Selden committed Jan 6, 2014
1 parent 71d60df commit db0e771
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions platform/posts/postsPersistence.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
var db = require('../db');

exports.createPost = function *(userId, title){
var results = yield [ db.sequelize.Post.create({ title: title }), db.sequelize.User.find(userId) ];
var post = results[0];
var user = results[1];
yield user.setPosts([post]);
var tasks = yield {
post: db.sequelize.Post.create({ title: title }),
user: db.sequelize.User.find(userId)
};

var user = tasks.user;
var post = tasks.post;

if(user && post){
yield user.setPosts([post]);
}

return post;
};

Expand Down

0 comments on commit db0e771

Please sign in to comment.