Trycatch: Async try catch for node.js
github.com1 pointsby CrabDude-1 comments
trycatch(function(){
process.nextTick(function() {
throw new Error("This will be caught.");
});
}, function(e) {
console.log(e.stack);
});
I also integrated it into the step module to create "stepup" which adds error coalescing, http://github.com/crabdude/stepup . var step = require('step');
function huntMen(buffy) {
var soulmates = [];
step(function() {
var group = this.group();
while (soulmates.length < 10) {
// Self-executing for closure
(function() {
var cb = group();
step(function() {
// Get 10 candidates for Buffy
getMatches(buffy, 10, this);
}, function(err, userids) {
// don't check userids.length on each loop iteration
for (var i = 0, l = userids.length; u = userids[i], i < l; i++) {
// Self-executing for closure, or use userids.forEach
(function() {
step(function() {
// get their pic from our pic server
getThumbnail (u, this);
}, function(err, thumb) {
thumb2 = thumb;
// ask our pic analyzer to review
isPicAVampire(thumb, this);
}, function (err, is_vamp) {
if (! is_vamp) {
// get 2 more pieces of info
getPersonality(u, this.parallel());
getLastTalked (u, match, this.parallel());
} else cb();
}, function (err, personality, last_talked) {
soulmates.push({
"userid" : match, // match does not exist in example code
"thumb" : thumb2,
"last_talked" : last_talked,
"personality" : personality
});
cb();
});
})();
}
});
})();
}
}, function(err) {
//
// Our function can now continue to do
// whatever it wants with
// soulmates...
//
});
} function User(first, last) {
if ( !(this instanceof User) )
return new User(first, last);
// constructor logic
}
Or a more robust slightly less "performant" version: function User(first, last) {
if ( !(this instanceof arguments.callee) )
return new arguments.callee(arguments[0],...);
// constructor logic
}
Note: arguments.callee is less "performant" than using a named function, but it does allow the 2 lines to be copied and pasted without alteration.
The problem is the hot dog stand doesn't want these Indie hot dogs, or at least they're not enough to make the big hot dog stand dollars the stand owner is after. When all your customers demand music label hot dogs, it's the labels that get to set the price, not the competitors; all of this is simple supply and demand.
Further, incumbent market forces are not defeated by competing with their strengths (content licensing), but instead historically must be defeated through indirect pressures. The labels like any business either answer to the marketplace or they will eventually go bankrupt offering a product nobody wants: CDs in a streaming world. The answer to disrupting the market is by either beating them at their own game by being a better label attracting all the artists to yourself and then offering a service of your own, or by empowering future content creators to the point that they no longer need or want the service the labels offer.
Sure, those Indie dogs might not taste as good as the sirloin label dogs, but at a tenth the price, twice the size and free delivery, I'd say, "What label dogs?"