-
-
Notifications
You must be signed in to change notification settings - Fork 195
Description
On the following example when i call dpp::when_any without adding a sleep raceResult.index() returns 18446744073709551615.
with the line co_await event.from()->creator->co_sleep(1); raceResult.index() returns 0 which is the correct desired value, as it represent the index of the task finished.
The data returned by raceResult.index() is index_finished:
DPP/include/dpp/coro/when_any.h
Lines 190 to 193 in 2ac5099
| /** | |
| * @brief Index of the awaitable that finished. Initialized to the maximum value of std::size_t. | |
| */ | |
| size_t index_finished = std::numeric_limits<std::size_t>::max(); |
As its returning 18446744073709551615 which is the initialized value, its not getting the finished task index correctly.
dpp::task<std::string> App::test(const dpp::slashcommand_t& event)
{
//co_await event.from()->creator->co_sleep(1);
co_return "test";
}
dpp::task<void> App::replyThinking(const dpp::slashcommand_t& event, std::function<task<std::string>(const dpp::slashcommand_t&)> func, bool ephemeral)
{
try
{
event.thinking(ephemeral);
auto raceResult = co_await dpp::when_any(
func(event), // Task 0: actual work
event.from()->creator->co_sleep(10) // Task 1: timeout timer
);
// 0 (work) finished before the timeout
raceResult.index() == 0 ? event.edit_response(message(raceResult.get<0>()))
: event.edit_response(message("Sorry, the operation timed out."));
}
catch (const task_cancelled_exception& e)
{
event.edit_response(message("Operation cancelled: " + std::string(e.what())));
}
catch (const std::exception& e)
{
event.edit_response(message("An error occurred: " + std::string(e.what())));
}
catch (...)
{
event.edit_response(message("An unknown error occurred."));
}
}
dpp::task<void> App::onSlashCommand(const slashcommand_t& event)
{
co_await replyThinking(event, std::bind_front(&App::test, this), true);
co_return;
}I'm debugging with Visual Studio 2022 version 17.14.0 Preview 2.0, Win10, the issue reproduces when testing with discord desktop/web
The lib was compiled using vcpkg, dpp:x64-windows 10.1.2