proxygen
Subscription.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <glog/logging.h>
20 
21 #include <wangle/deprecated/rx/types.h> // must come first
23 
24 namespace wangle {
25 
26 template <class T>
27 class Subscription {
28  public:
29  Subscription() = default;
30 
31  Subscription(const Subscription&) = delete;
32 
34  *this = std::move(other);
35  }
36 
38  unsubscribe();
39  unsubscriber_ = std::move(other.unsubscriber_);
40  id_ = other.id_;
41  other.unsubscriber_ = nullptr;
42  other.id_ = 0;
43  return *this;
44  }
45 
47  unsubscribe();
48  }
49 
50  private:
52 
53  Subscription(std::shared_ptr<Unsubscriber> unsubscriber, uint64_t id)
54  : unsubscriber_(std::move(unsubscriber)), id_(id) {
55  CHECK(id_ > 0);
56  }
57 
58  void unsubscribe() {
59  if (unsubscriber_ && id_ > 0) {
60  unsubscriber_->unsubscribe(id_);
61  id_ = 0;
62  unsubscriber_ = nullptr;
63  }
64  }
65 
66  std::shared_ptr<Unsubscriber> unsubscriber_;
68 
69  friend class Observable<T>;
70 };
71 
72 } // namespace wangle
#define T(v)
Definition: http_parser.c:233
Subscription(Subscription &&other) noexcept
Definition: Subscription.h:33
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
STL namespace.
Observable< T >::Unsubscriber Unsubscriber
Definition: Subscription.h:51
requires E e noexcept(noexcept(s.error(std::move(e))))
Subscription & operator=(Subscription &&other) noexcept
Definition: Subscription.h:37
Subscription(std::shared_ptr< Unsubscriber > unsubscriber, uint64_t id)
Definition: Subscription.h:53
std::shared_ptr< Unsubscriber > unsubscriber_
Definition: Subscription.h:66