proxy: support value expiration

This commit is contained in:
Adrien Béraud committed 2018-10-29 12:45:52 -04:00
1 parent b7b5152348
commit ff83a6daab
3 files changed
+20 -10

No files matched your search

+3 -2
View File
@@ -706,11 +706,12 @@ DhtProxyClient::sendListen(const std::shared_ptr<restbed::Request>& req, const V
Json::CharReaderBuilder rbuilder;
auto reader = std::unique_ptr<Json::CharReader>(rbuilder.newCharReader());
if (reader->parse(body.data(), body.data() + body.size(), &json, &err)) {
auto expired = json.get("expired", Json::Value(false)).asBool();
auto value = std::make_shared<Value>(json);
if ((not filter or filter(*value)) and cb) {
std::lock_guard<std::mutex> lock(lockCallbacks);
callbacks_.emplace_back([cb, value, state]() {
if (not state->cancel and not cb({value}, false))
callbacks_.emplace_back([cb, value, state, expired]() {
if (not state->cancel and not cb({value}, expired))
state->cancel = true;
});
loopSignal_();