ReactivePlusPlus
ReactiveX implementation for C++20
Loading...
Searching...
No Matches
finally.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
11#pragma once
12
13#include <rpp/operators/fwd.hpp>
14
15#include <rpp/defs.hpp>
16#include <rpp/operators/details/strategy.hpp>
17
18namespace rpp::operators::details
19{
20 template<rpp::constraint::decayed_type LastFn>
21 struct finally_t
22 {
23 template<rpp::constraint::decayed_type T>
25 {
26 using result_type = T;
27 };
28
29 template<rpp::details::observables::constraint::disposables_strategy Prev>
30 using updated_optimal_disposables_strategy = typename Prev::template add<1>;
31
32 RPP_NO_UNIQUE_ADDRESS LastFn last_fn;
33
34 template<rpp::constraint::decayed_type Type, rpp::constraint::observer Observer>
35 auto lift(Observer&& observer) const
36 {
37 observer.set_upstream(make_callback_disposable(last_fn));
38 return std::forward<Observer>(observer);
39 }
40 };
41} // namespace rpp::operators::details
42
43namespace rpp::operators
44{
56 template<rpp::constraint::is_nothrow_invocable LastFn>
57 auto finally(LastFn&& last_fn)
58 {
59 return details::finally_t<std::decay_t<LastFn>>{std::forward<LastFn>(last_fn)};
60 }
61} // namespace rpp::operators
void set_upstream(const disposable_wrapper &d) noexcept
Observable calls this method to pass disposable. Observer disposes this disposable WHEN observer want...
Definition observer.hpp:49
Base class for any observer used in RPP. It handles core callbacks of observers. Objects of this clas...
Definition observer.hpp:172
Definition finally.hpp:22