mirror of
https://github.com/savoirfairelinux/opendht.git
synced 2026-11-08 12:28:42 +00:00
http: add Request::await
This commit is contained in:
1 parent
1778f64048
commit
c84fac6823
2 files changed
+19
No files matched your search
@@ -290,6 +290,9 @@ public:
|
||||
|
||||
void send();
|
||||
|
||||
/** Send and block for response */
|
||||
const Response& await();
|
||||
|
||||
/**
|
||||
* User action to cancel the Request and call the completion callbacks.
|
||||
*/
|
||||
|
||||
@@ -1096,5 +1096,21 @@ Request::getRelativePath(const Url& origin, const std::string& path)
|
||||
return newPath.toString();
|
||||
}
|
||||
|
||||
const Response&
|
||||
Request::await()
|
||||
{
|
||||
std::mutex mtx;
|
||||
std::unique_lock<std::mutex> lock(mtx);
|
||||
std::condition_variable cv;
|
||||
bool ok {false};
|
||||
add_on_done_callback([&](const Response& resp){
|
||||
std::lock_guard<std::mutex> lk(mtx);
|
||||
ok = true;
|
||||
cv.notify_all();
|
||||
});
|
||||
cv.wait(lock, [&]{ return ok; });
|
||||
return response_;
|
||||
}
|
||||
|
||||
} // namespace http
|
||||
} // namespace dht
|
||||
Reference in new issue
Block a user