forked from rsocket/rsocket-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSingleSubscriber.cpp
More file actions
63 lines (52 loc) · 1.57 KB
/
SingleSubscriber.cpp
File metadata and controls
63 lines (52 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright 2004-present Facebook. All Rights Reserved.
#include "tck-test/SingleSubscriber.h"
#include <thread>
#include <folly/Format.h>
using namespace folly;
namespace rsocket {
namespace tck {
void SingleSubscriber::request(int n) {
LOG(INFO) << "... requesting " << n << ". No request() for Single.";
}
void SingleSubscriber::cancel() {
LOG(INFO) << "... canceling ";
canceled_ = true;
if (auto subscription = std::move(subscription_)) {
subscription->cancel();
}
}
void SingleSubscriber::onSubscribe(
yarpl::Reference<yarpl::single::SingleSubscription> subscription) noexcept {
VLOG(4) << "OnSubscribe in SingleSubscriber";
subscription_ = subscription;
}
void SingleSubscriber::onSuccess(Payload element) noexcept {
LOG(INFO) << "... received onSuccess from Publisher: " << element;
{
std::unique_lock<std::mutex> lock(mutex_);
std::string data =
element.data ? element.data->moveToFbString().toStdString() : "";
std::string metadata = element.metadata
? element.metadata->moveToFbString().toStdString()
: "";
values_.push_back(std::make_pair(data, metadata));
++valuesCount_;
}
valuesCV_.notify_one();
{
std::unique_lock<std::mutex> lock(mutex_);
completed_ = true;
}
terminatedCV_.notify_one();
}
void SingleSubscriber::onError(folly::exception_wrapper ex) noexcept {
LOG(INFO) << "... received onError from Publisher";
{
std::unique_lock<std::mutex> lock(mutex_);
errors_.push_back(std::move(ex));
errored_ = true;
}
terminatedCV_.notify_one();
}
} // tck
} // reactivesocket