4 ms·
The 'pyramid of doom' is one of my pain points with node right now. The article's solution is to push the anonymous functions out into separate named functions
by 727374 13y ago
The 'pyramid of doom' is one of my pain points with node right now. The article's solution is to push the anonymous functions out into separate named functions, but this just adds more code. Would have been awesome to use promises instead.
- danenania 13y agoThe async library (https://github.com/caolan/async https://github.com/caolan/async) offers many excellent tools for staying out of callback hell. After using it one project, I can't imagine trying to write heavily async javascript without it.
- babby 13y agoAll I have to say guys; promises + generators. My god, it's absolutely delicious. Seriously, just learn it. Get your --harmony flag on. It will be in browsers soon enough as well. It's literally the future of javascript and having converted some of my codebase to promises + generators instead of just promises. Wow. It felt amazing. Suddenly everything doesn't look like spaghetti. I use bluebird for promises and a custom dev fork of Coffeescript that allows for generators. You do have to wrap your anonymous functions with "Promise.coroutine", but thats really it. You could always just not even use promises, and go plain generators too.
- 727374 13y agoIf I promisify some code with bluebird, can I use it with Mongoose's built in promises? Or will promises from different libraries explode when they touch?
- babby 13y agoWell promises are suppose to be compatible with one another due to adhering to rules. Should be A-OK. Bluebird is just, at the moment, the most performant Promise library, and they seem to be building their API as close to what native Promises will be like. You could really use any promise library and it wouldn't matter much, perhaps use the one that mongoose uses if it's an issue.