Skip to content

Instantly share code, notes, and snippets.

@designfrontier
Last active August 29, 2015 14:25
Show Gist options
  • Save designfrontier/fb95b0a212f55554a09b to your computer and use it in GitHub Desktop.
Save designfrontier/fb95b0a212f55554a09b to your computer and use it in GitHub Desktop.
bernstein real world-ish with pseudo code
var userCreationStack = bernstein.create([
function (data, orig, next){
var imageProm = imageServiceWrapper.sliceAndDice(data.image);
imageProm.then(function (imageData) {
data.images = imageData;
next(data);
});
}
, function (data, orig, next) {
next(data.quote = getRandomQuote());
}
, function (data, orig) {
data.type = "free";
data.createdData = new Date();
data.interactions = 0;
return new Promise(function (resolve, reject) {
var userProm = userService.save(data);
userProm.then(function (userObj) {
resolve(userObj);
});
});
}
]);
//inside some handler for a route...
var user = userCreationStack(req.body);
user.then(function (data) {
response.send(data);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment