mirror of https://github.com/procxx/kepka.git
Simplify rpl::consumer.
This commit is contained in:
parent
53de44f272
commit
fde3ff1bbf
|
@ -38,25 +38,6 @@ class consumer_handlers;
|
||||||
template <typename Value, typename Error>
|
template <typename Value, typename Error>
|
||||||
class type_erased_handlers {
|
class type_erased_handlers {
|
||||||
public:
|
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(Value &&value) = 0;
|
||||||
virtual bool put_next_copy(const Value &value) = 0;
|
virtual bool put_next_copy(const Value &value) = 0;
|
||||||
virtual void put_error(Error &&error) = 0;
|
virtual void put_error(Error &&error) = 0;
|
||||||
|
@ -70,6 +51,8 @@ public:
|
||||||
|
|
||||||
void terminate();
|
void terminate();
|
||||||
|
|
||||||
|
virtual ~type_erased_handlers() = default;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
lifetime _lifetime;
|
lifetime _lifetime;
|
||||||
bool _terminated = false;
|
bool _terminated = false;
|
||||||
|
@ -107,20 +90,6 @@ public:
|
||||||
, _done(std::forward<OnDoneOther>(done)) {
|
, _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(Value &&value) final override;
|
||||||
bool put_next_copy(const Value &value) final override;
|
bool put_next_copy(const Value &value) final override;
|
||||||
void put_error(Error &&error) 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(
|
inline consumer_base<Value, Error, Handlers>::consumer_base(
|
||||||
OnNext &&next,
|
OnNext &&next,
|
||||||
OnError &&error,
|
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<OnNext>(next),
|
||||||
std::forward<OnError>(error),
|
std::forward<OnError>(error),
|
||||||
std::forward<OnDone>(done))) {
|
std::forward<OnDone>(done))) {
|
||||||
|
|
|
@ -24,6 +24,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||||
#include <rpl/range.h>
|
#include <rpl/range.h>
|
||||||
#include <rpl/then.h>
|
#include <rpl/then.h>
|
||||||
#include <rpl/range.h>
|
#include <rpl/range.h>
|
||||||
|
#include <algorithm>
|
||||||
#include "base/algorithm.h"
|
#include "base/algorithm.h"
|
||||||
#include "base/assertion.h"
|
#include "base/assertion.h"
|
||||||
#include "base/index_based_iterator.h"
|
#include "base/index_based_iterator.h"
|
||||||
|
|
|
@ -21,6 +21,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <rpl/producer.h>
|
#include <rpl/producer.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace rpl {
|
namespace rpl {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue