Skip to content

Commit a9e6c32

Browse files
authored
Merge pull request #4448 from Goober5000/async_mprintfs
add some logging to waitAsync
2 parents 07b6c17 + 2ce953a commit a9e6c32

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

code/osapi/outwnd.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ static const char *FILTERS_ENABLED_BY_DEFAULT[] =
2929
{
3030
"error",
3131
"warning",
32-
"general"
32+
"general",
33+
"scripting"
3334
};
3435

3536
struct outwnd_filter_struct {

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+
nprintf(("scripting", "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+
nprintf(("scripting", "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)