Promises monitoring functionality

195 views
Skip to first unread message

Alexander Bolshakov

unread,
Nov 1, 2015, 3:48:52 AM11/1/15
to bluebird
Hello,

I would like to implement promises monitoring functionality for bluebird: this would allow to see list of all pending promises at any moment, which could be helpful for tracing unfinished promises chains and detecting promises loops. I have 2 questions regarding this topic:

1) Would such a feature and corresponding toggle flag be accepted as contribution to bluebird?
2) I have found hook promiseCreated, what is most appropriate place in source to place corresponding hook? Currently I am thinking of _setFulfilled, _setRejected and _setCancelled methods of Promise.

Thanks.

Petka Antonov

unread,
Nov 1, 2015, 6:00:03 AM11/1/15
to bluebird
Yes such functionality would be accepted.

For minimum performance loss when the feature is not used, you should create noop methods and then overwrite the methods when the feature is activated.

Those are appropriate places to place the hook yea.

_promiseChained() could be placed inside ._then() in the case where !haveInternalData.

_promiseCreated() is also overwritten inside context.js, so remember that.

baf...@gmail.com

unread,
Oct 25, 2016, 8:01:24 AM10/25/16
to bluebird
Hi,

Does anybody know if there has been any progress on this feature?

I see that 'promise monitoring' has been implemented in the form of events, but it doesn't seem that anybody has consolidated these events so as to enumerate all pending promises (and ideally give their stack traces).  They also seem undocumented.

I can't see the fork network on github because there are too many for github to display, but I would like to track this feature and perhaps contribute.

Alexander Bolshakov

unread,
Oct 25, 2016, 8:14:42 AM10/25/16
to bluebird
Hi,

The feature that entered bluebird supplies hooks (Promise life cycle events) for bluebird users that allow to implement the mentioned debugging functionality. This feature is documented: http://bluebirdjs.com/docs/features.html#promise-monitoring. To keep the library lightweight and simple the decision was not to include this debugging functionality (list all pending promises e.t.c.) itself into the library. If there is a good reason to publish this functionality separately from bluebird we can talk about this.

Regards,
Alexander

baf...@gmail.com

unread,
Oct 25, 2016, 8:55:03 AM10/25/16
to bluebird
Thanks Alexander.

I couldn't seem to figure out how to implement this feature from the linked documentation.  Has anybody done this yet?

After running some tests, it doesn't seem like the API provides quite enough information, but I don't fully understand what I'm looking at yet.

Is the specific behavior of the 'dummy' promises that dispatch promiseChained documented anywhere?  They seem to be created for both throw and catch, without indication of which one it is.

Alexander Bolshakov

unread,
Oct 25, 2016, 9:49:02 AM10/25/16
to bluebird
I have implemented this functionality, some outdated version of it can be found here :https://github.com/lextiz/bluebird/blob/cleanMonitor/src/extended_debuggability.js#L62. In this version "util.hookTo" would have to be replaced with standard subscription mechanism described here: http://bluebirdjs.com/docs/features.html#promise-monitoring. It would take efforts form me to release this extended debugging functionality as a separate open source (possibly chromium extension), this is the reason I did not do it yet. Basic idea is to use "promiseCreated" and "promiseFulfilled" events to add and remove promises from a set, this set would contain all pending promises at certain moment. 

baf...@gmail.com

unread,
Oct 26, 2016, 11:58:58 AM10/26/16
to bluebird
Thanks.  I was missing one of the hooks.

For future readers, every creation of a promise triggers "promiseCreated".  If the promise is created in response to a "then" etc, it will also trigger a "promiseChained", but this is unrelated to tracking the number of pending promises.

A promise will be destroyed in 1 of 4 different ways: it is either fulfilled, rejected, resolved, or canceled.  Any of the 4 equivalent events indicate a promise is leaving the pending state.
Reply all
Reply to author
Forward
0 new messages