Commit 1588071c authored by Dominik Charousset's avatar Dominik Charousset

Allow subscribing to flows with std::ignore

parent d2e4180a
......@@ -470,6 +470,11 @@ disposable observable<T>::subscribe(async::producer_resource<T> resource) {
}
}
template <class T>
disposable observable<T>::subscribe(ignore_t) {
return subscribe(observer<T>::ignore());
}
template <class T>
template <class OnNext>
disposable observable<T>::for_each(OnNext on_next) {
......
......@@ -15,6 +15,7 @@
#include "caf/intrusive_ptr.hpp"
#include <cstddef>
#include <tuple>
#include <utility>
#include <vector>
......@@ -32,6 +33,9 @@ public:
/// The pointer-to-implementation type.
using pimpl_type = intrusive_ptr<op::base<T>>;
/// Type for drop-all subscribers.
using ignore_t = decltype(std::ignore);
// -- constructors, destructors, and assignment operators --------------------
explicit observable(pimpl_type pimpl) noexcept : pimpl_(std::move(pimpl)) {
......@@ -57,6 +61,9 @@ public:
/// Creates a new observer that pushes all observed items to the resource.
disposable subscribe(async::producer_resource<T> resource);
/// Subscribes a new observer to the items emitted by this observable.
disposable subscribe(ignore_t);
/// Calls `on_next` for each item emitted by this observable.
template <class OnNext>
disposable for_each(OnNext on_next);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment