|
|
|
|
|
by dmitrig01
4439 days ago
|
|
There are several promise libraries (the most promising among them seems to be Bluebird, though Q has some popularity as well), which can easily convert callback-style functions into promises. For example: var b = require('bluebird'), request = b.promisify(require('request'));
request(...).then(...)
These libraries also have utilities for controlling callback flow -- e.g calling several promises in parallel, which is done in the article with jQuery's $.when, waiting until a certain number finish, etc |
|
When I used promises for real in a section of my code processing data:
1) I found it hard to use mostly because of all the work I had to do to "lift" non promise code up into promises, before I could use them.
2) When chaining them, it wasn't clear how you would handle a "fan-out", where a piece of data generated an array, which you then had to process with callbacks.
3) Unless I inserted a fail() after every then(), it was hard to tell where exactly in the chain something failed, and the stack trace wasn't very helpful.
I suspect maybe I'm doing something wrong--that even though you can chain promises sequentially, you generally want to make functions using promises, that you can then chain? I still haven't seen well written promise code. Anyone got examples other than toy examples?