Skip to content

Commit e84c66d

Browse files
authored
fix: dpp::cluster::register_command with coroutine handler on windows (#1504)
1 parent 7394b84 commit e84c66d

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

include/dpp/cluster.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,12 @@ class DPP_EXPORT cluster {
587587
* @return bool Returns `true` if the command was registered successfully, or `false` if
588588
* the command with the same name already exists
589589
*/
590-
bool register_command(const std::string& name, const slashcommand_handler_t handler);
590+
template <typename F>
591+
std::enable_if_t<utility::callable_returns_v<F, void, const slashcommand_t&>, bool> register_command(const std::string& name, F&& handler) {
592+
std::unique_lock lk(named_commands_mutex);
593+
auto [_, inserted] = named_commands.try_emplace(name, std::forward<F>(handler));
594+
return inserted;
595+
}
591596

592597
/**
593598
* @brief Get the number of currently active HTTP(S) requests active in the cluster.
@@ -608,12 +613,12 @@ class DPP_EXPORT cluster {
608613
* the command with the same name already exists.
609614
*/
610615
template <typename F>
611-
std::enable_if_t<std::is_same_v<std::invoke_result_t<F, const slashcommand_handler_t&>, dpp::task<void>>, bool>
612-
register_command(const std::string& name, F&& handler){
616+
requires (utility::callable_returns<F, dpp::task<void>, const slashcommand_t&>)
617+
bool register_command(const std::string& name, F&& handler) {
613618
std::unique_lock lk(named_commands_mutex);
614-
auto [_, inserted] = named_commands.try_emplace(name, std::forward<F>(handler));
619+
auto [_, inserted] = named_commands.try_emplace(name, std::in_place_type<co_slashcommand_handler_t>, std::forward<F>(handler));
615620
return inserted;
616-
};
621+
}
617622
#endif
618623

619624
/**

src/dpp/cluster.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -638,12 +638,6 @@ cluster& cluster::set_request_timeout(uint16_t timeout) {
638638
return *this;
639639
}
640640

641-
bool cluster::register_command(const std::string &name, const slashcommand_handler_t handler) {
642-
std::unique_lock lk(named_commands_mutex);
643-
auto [_, inserted] = named_commands.try_emplace(name, handler);
644-
return inserted;
645-
}
646-
647641
bool cluster::unregister_command(const std::string &name) {
648642
std::unique_lock lk(named_commands_mutex);
649643
return named_commands.erase(name) == 1;

0 commit comments

Comments
 (0)