Simplify rpl::consumer.

This commit is contained in:
John Preston 2017-10-27 11:51:11 +03:00
parent 53de44f272
commit fde3ff1bbf
3 changed files with 11 additions and 34 deletions

View File

@ -38,25 +38,6 @@ class consumer_handlers;
template <typename Value, typename Error>
class type_erased_handlers {
public:
template <
typename OnNext,
typename OnError,
typename OnDone>
static std::shared_ptr<type_erased_handlers> create(
OnNext &&next,
OnError &&error,
OnDone &&done) {
return std::make_shared<consumer_handlers<
Value,
Error,
std::decay_t<OnNext>,
std::decay_t<OnError>,
std::decay_t<OnDone>>>(
std::forward<OnNext>(next),
std::forward<OnError>(error),
std::forward<OnDone>(done));
}
virtual bool put_next(Value &&value) = 0;
virtual bool put_next_copy(const Value &value) = 0;
virtual void put_error(Error &&error) = 0;
@ -70,6 +51,8 @@ public:
void terminate();
virtual ~type_erased_handlers() = default;
protected:
lifetime _lifetime;
bool _terminated = false;
@ -107,20 +90,6 @@ public:
, _done(std::forward<OnDoneOther>(done)) {
}
template <
typename OnNextOther,
typename OnErrorOther,
typename OnDoneOther>
static std::shared_ptr<consumer_handlers> create(
OnNextOther &&next,
OnErrorOther &&error,
OnDoneOther &&done) {
return std::make_shared<consumer_handlers>(
std::forward<OnNextOther>(next),
std::forward<OnErrorOther>(error),
std::forward<OnDoneOther>(done));
}
bool put_next(Value &&value) final override;
bool put_next_copy(const Value &value) final override;
void put_error(Error &&error) final override;
@ -389,7 +358,13 @@ template <typename OnNext, typename OnError, typename OnDone>
inline consumer_base<Value, Error, Handlers>::consumer_base(
OnNext &&next,
OnError &&error,
OnDone &&done) : _handlers(Handlers::create(
OnDone &&done)
: _handlers(std::make_shared<consumer_handlers<
Value,
Error,
std::decay_t<OnNext>,
std::decay_t<OnError>,
std::decay_t<OnDone>>>(
std::forward<OnNext>(next),
std::forward<OnError>(error),
std::forward<OnDone>(done))) {

View File

@ -24,6 +24,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include <rpl/range.h>
#include <rpl/then.h>
#include <rpl/range.h>
#include <algorithm>
#include "base/algorithm.h"
#include "base/assertion.h"
#include "base/index_based_iterator.h"

View File

@ -21,6 +21,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#pragma once
#include <rpl/producer.h>
#include <vector>
namespace rpl {