ReactivePlusPlus
ReactiveX implementation for C++20
Loading...
Searching...
No Matches
defer.hpp
1// ReactivePlusPlus library
2//
3// Copyright Aleksey Loginov 2023 - present.
4// Distributed under the Boost Software License, Version 1.0.
5// (See accompanying file LICENSE_1_0.txt or copy at
6// https://www.boost.org/LICENSE_1_0.txt)
7//
8// Project home: https://github.com/victimsnino/ReactivePlusPlus
9
10#pragma once
11
12#include <rpp/sources/fwd.hpp>
13
14#include <rpp/defs.hpp>
15#include <rpp/observables/observable.hpp>
16
17namespace rpp::details
18{
19 template<typename Factory>
21 {
22 using value_type = rpp::utils::extract_observable_type_t<std::invoke_result_t<Factory>>;
23 using optimal_disposables_strategy = typename std::invoke_result_t<Factory>::optimal_disposables_strategy;
24
25 RPP_NO_UNIQUE_ADDRESS Factory observable_factory;
26
27 template<rpp::constraint::observer_of_type<value_type> TObs>
28 void subscribe(TObs&& obs) const
29 {
30 observable_factory().subscribe(std::forward<TObs>(obs));
31 }
32 };
33} // namespace rpp::details
34
35namespace rpp
36{
37 template<constraint::decayed_type Type, typename Factory>
39} // namespace rpp
40
41namespace rpp::source
42{
43
55 template<std::invocable Factory>
57 auto defer(Factory&& observable_factory)
58 {
59 return defer_observable<rpp::utils::extract_observable_type_t<std::invoke_result_t<Factory>>, Factory>{std::forward<Factory>(observable_factory)};
60 }
61} // namespace rpp::source
Base class for any observable used in RPP. It handles core callbacks of observable.
Definition observable.hpp:38
Definition fwd.hpp:80
auto defer(Factory &&observable_factory)
Creates rpp::observable that calls the specified observable factory to create an observable for each ...
Definition defer.hpp:57
Definition defer.hpp:21