Skip to content
Snippets Groups Projects
Commit b22c04c6 authored by Stephen R. van den Berg's avatar Stephen R. van den Berg
Browse files

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

parent 2d93703d
Branches
Tags
No related merge requests found
#pike __REAL_VERSION__ #pike __REAL_VERSION__
// Enable CONCURRENT_DEBUG to get more meaningful broken-promise messages
#define CONCURRENT_DEBUG 0
//! Module for handling multiple concurrent events. //! Module for handling multiple concurrent events.
//! //!
//! The @[Future] and @[Promise] API was inspired by //! The @[Future] and @[Promise] API was inspired by
...@@ -834,6 +838,9 @@ class Promise ...@@ -834,6 +838,9 @@ class Promise
final int _materialised; final int _materialised;
final AggregateState _astate; final AggregateState _astate;
#if CONCURRENT_DEBUG
array(Pike.BacktraceFrame) createdat;
#endif
//! Creates a new promise, optionally initialised from a traditional callback //! Creates a new promise, optionally initialised from a traditional callback
//! driven method via @expr{executor(success, failure, @@extra)@}. //! driven method via @expr{executor(success, failure, @@extra)@}.
...@@ -844,6 +851,9 @@ class Promise ...@@ -844,6 +851,9 @@ class Promise
function(function(mixed:void), function(function(mixed:void),
function(mixed:void), mixed ...:void) executor, mixed ... extra) function(mixed:void), mixed ...:void) executor, mixed ... extra)
{ {
#if CONCURRENT_DEBUG
createdat = backtrace()[..<1];
#endif
state = STATE_NO_FUTURE; state = STATE_NO_FUTURE;
if (executor) if (executor)
executor(success, failure, @extra); executor(success, failure, @extra);
...@@ -1149,7 +1159,11 @@ class Promise ...@@ -1149,7 +1159,11 @@ class Promise
{ {
// NB: Don't complain about dropping STATE_NO_FUTURE on the floor. // NB: Don't complain about dropping STATE_NO_FUTURE on the floor.
if (state == STATE_PENDING) 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) if ((state == STATE_REJECTED) && global_on_failure)
call_callback(global_on_failure, result); call_callback(global_on_failure, result);
result = UNDEFINED; result = UNDEFINED;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment