Skip to content

Commit 05f71a3

Browse files
committed
add some logging to waitAsync
Log when the context is created, completes, and is aborted. Adds insight for the situation described in #4432.
1 parent 5dfef48 commit 05f71a3

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

code/scripting/api/LuaPromise.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ LuaPromise::LuaPromise(const std::shared_ptr<resolve_context>& resolveContext) :
9292
{
9393
m_state->state = State::Pending;
9494

95-
// This executes promises eagerly since registering the callback kicks of the async operation
95+
// This executes promises eagerly since registering the callback kicks off the async operation
9696
m_state->registerResolveCallback(resolveContext);
9797
}
9898

code/scripting/api/libs/async.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ ADE_FUNC(promise,
111111
"function(function(any resolveVal) => void resolve, function(any errorVal) => void reject) => void body",
112112
"Creates a promise that resolves when the resolve function of the callback is called or errors if the reject "
113113
"function is called. The function will be called "
114-
"on it's own.",
114+
"on its own.",
115115
"promise",
116116
"The promise or nil on error")
117117
{

code/scripting/api/libs/mission.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1729,19 +1729,25 @@ ADE_FUNC(waitAsync,
17291729
17301730
class time_resolve_context : public resolve_context, public std::enable_shared_from_this<time_resolve_context> {
17311731
public:
1732-
time_resolve_context(int timestamp) : m_timestamp(timestamp) {}
1732+
time_resolve_context(int timestamp) : m_timestamp(timestamp) {
1733+
static int unique_id_counter = 0;
1734+
m_unique_id = unique_id_counter++;
1735+
mprintf(("waitAsync: Creating asynchronous context %d.\n", m_unique_id));
1736+
}
17331737
void setResolver(Resolver resolver) override
17341738
{
17351739
// Keep checking the time until the timestamp is elapsed
17361740
auto self = shared_from_this();
17371741
auto cb = [this, self, resolver](
17381742
executor::IExecutionContext::State contextState) {
17391743
if (contextState == executor::IExecutionContext::State::Invalid) {
1744+
mprintf(("waitAsync: Context is invalid, possibly due to a game state change (current state is %s). Aborting asynchronous context %d.\n", GS_state_text[gameseq_get_state()], m_unique_id));
17401745
resolver(true, luacpp::LuaValueList());
17411746
return executor::Executor::CallbackResult::Done;
17421747
}
17431748

17441749
if (timestamp_elapsed(m_timestamp)) {
1750+
mprintf(("waitAsync: Timestamp has elapsed for asynchronous context %d.\n", m_unique_id));
17451751
resolver(false, luacpp::LuaValueList());
17461752
return executor::Executor::CallbackResult::Done;
17471753
}
@@ -1756,6 +1762,7 @@ ADE_FUNC(waitAsync,
17561762

17571763
private:
17581764
int m_timestamp = -1;
1765+
int m_unique_id = -1;
17591766
};
17601767
return ade_set_args(L,
17611768
"o",

0 commit comments

Comments
 (0)