add operator() overload for defered message that sends reply

This commit is contained in:
Jeff Becker 2021-09-24 16:01:31 -04:00
parent e1b1a84c4b
commit 5a41e84378
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05
2 changed files with 10 additions and 1 deletions

View File

@ -75,6 +75,15 @@ public:
explicit DeferredSend(Message& m) : oxenmq{m.oxenmq}, conn{m.conn}, reply_tag{m.reply_tag} {}
template <typename... Args>
void operator()(Args &&...args) const {
if (reply_tag.empty())
back(std::forward<Args>(args)...);
else
reply(std::forward<Args>(args)...);
};
/// Equivalent to msg.send_back(...), but can be invoked later.
template <typename... Args>
void back(std::string_view command, Args&&... args) const;

View File

@ -472,7 +472,7 @@ TEST_CASE("deferred replies", "[commands][send][deferred]") {
{ auto lock = catch_lock(); UNSCOPED_INFO("sleeping"); }
std::this_thread::sleep_for(50ms * TIME_DILATION);
{ auto lock = catch_lock(); UNSCOPED_INFO("sending"); }
send.reply(msg);
send(msg);
}};
t.detach();
});