Skip to content
Snippets Groups Projects
Commit 37c732b7 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

http: add Request::await

parent 1778f640
No related branches found
No related tags found
No related merge requests found
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment