Concurrent: Add CONCURRENT_DEBUG to get more meaningful broken-promises.

parent 97ff7313
#pike __REAL_VERSION__
// Enable CONCURRENT_DEBUG to get more meaningful broken-promise messages
#define CONCURRENT_DEBUG 0
//! Module for handling multiple concurrent events.
//!
//! The @[Future] and @[Promise] API was inspired by
......@@ -880,6 +884,9 @@ class Promise
final int _materialised;
final AggregateState _astate;
#if CONCURRENT_DEBUG
array(Pike.BacktraceFrame) createdat;
#endif
//! Creates a new promise, optionally initialised from a traditional callback
//! driven method via @expr{executor(success, failure, @@extra)@}.
......@@ -890,6 +897,9 @@ class Promise
function(function(mixed:void),
function(mixed:void), mixed ...:void) executor, mixed ... extra)
{
#if CONCURRENT_DEBUG
createdat = backtrace()[..<1];
#endif
state = STATE_NO_FUTURE;
if (executor)
executor(success, failure, @extra);
......@@ -1195,7 +1205,11 @@ class Promise
{
// NB: Don't complain about dropping STATE_NO_FUTURE on the floor.
if (state == STATE_PENDING)
try_failure(({ sprintf("%O: Promise broken.\n", this), backtrace() }));
try_failure(({ sprintf("%O: Promise broken.\n", this),
#if CONCURRENT_DEBUG
this->createdat ||
#endif
backtrace() }));
if ((state == STATE_REJECTED) && global_on_failure)
call_callback(global_on_failure, result);
result = UNDEFINED;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment