Handling mongoose queries but with different JavaScript Promise implementations Handling mongoose queries but with different JavaScript Promise implementations mongoose mongoose

Handling mongoose queries but with different JavaScript Promise implementations


The best approach depends on your needs and the environment you are working in. Thus far you have not considered performance or security, only syntax and compatibility. If you need speed, low memory foot print, and trust the code then go with BlueBird. If you do not trust the code i.e. need security, do not mind a heavy memory footprint, and don't mind a nearly 10x slow down then go with Q.

Ref: https://github.com/petkaantonov/bluebird/issues/381


Good on you for testing the results for consistent behaviour. However, the question of which is the 'best approach' depends on what you are seeking.

If you are wanting the fastest result, you should test both scenarios yourself using your own code. You may find that one form will outperform the other slightly and consume less memory. You may also want to look at defer(), if it is supported, as it is sometimes significantly faster.

If speed is not key and your promise library doesn't have a clear convention, then the best pattern is the one that you find the easiest to read. Some people prefer promisifying wrappers (like your fnCall()) over creating a new Promise() over and over, and a lot of people seem to dislike defer() for some reason. But without a convincing performance argument, there is really no good answer.

The last thing worth considering is whether to stray from JS's native implementation of Promises at all, particularly in Node, now that it is officially supported. In this case, you are pretty much restricted to new Promise().