Skip to content

Commit fc035df

Browse files
committed
add max time to wait for ClearActivity
1 parent 8de7214 commit fc035df

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/discord/core.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,21 @@ void DiscordInstance::clear_activity(bool wait) {
124124
received_callback = true;
125125
});
126126

127+
using namespace std::chrono_literals;
128+
127129
if (wait) {
130+
131+
constexpr auto max_waittime = 1s;
132+
133+
const auto start_time = std::chrono::steady_clock::now();
134+
128135
while (not received_callback) {
129136
this->update();
130-
std::this_thread::sleep_for(std::chrono::milliseconds(1));
137+
std::this_thread::sleep_for(1ms);
138+
const auto now = std::chrono::steady_clock::now();
139+
if (now - start_time >= max_waittime) {
140+
break;
141+
}
131142
}
132143
}
133144
}

0 commit comments

Comments
 (0)