Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ set(SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/include/recpp/subscribers/MaybeSubscriber.h
${CMAKE_CURRENT_SOURCE_DIR}/include/recpp/subscribers/ObservableSubscriber.h
${CMAKE_CURRENT_SOURCE_DIR}/include/recpp/subscribers/SingleSubscriber.h
${CMAKE_CURRENT_SOURCE_DIR}/include/recpp/subscribers/inl/CompletableSubscriber.inl
${CMAKE_CURRENT_SOURCE_DIR}/include/recpp/subscribers/inl/DefaultSubscriber.inl
${CMAKE_CURRENT_SOURCE_DIR}/include/recpp/subscribers/inl/MaybeSubscriber.inl
${CMAKE_CURRENT_SOURCE_DIR}/include/recpp/subscribers/inl/ObservableSubscriber.inl
Expand Down
8 changes: 4 additions & 4 deletions examples/resource-loading/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Completable standardResourcesLoad(Context &context, const filesystem::path &path
error_code error;
const auto dirIterator = filesystem::directory_iterator(path, error);
if (error)
return Completable::error(make_exception_ptr(runtime_error(error.message())));
return Completable::error(runtime_error(error.message()));

for (const auto &entry : dirIterator)
{
Expand All @@ -77,7 +77,7 @@ Completable standardResourcesLoad(Context &context, const filesystem::path &path
if (!parseFromStream(builder, stream, &root, &errs))
{
cout << errs << endl;
return Completable::error(make_exception_ptr(runtime_error(errs)));
return Completable::error(runtime_error(errs));
}
}
return Completable::complete();
Expand All @@ -93,7 +93,7 @@ Completable rxResourcesLoad(Context &context, const filesystem::path &path)
const auto dirIterator = filesystem::directory_iterator(path, error);
if (error)
{
subscriber.onError(make_exception_ptr(runtime_error(error.message())));
subscriber.onError(runtime_error(error.message()));
return;
}

Expand All @@ -114,7 +114,7 @@ Completable rxResourcesLoad(Context &context, const filesystem::path &path)
if (!parseFromStream(builder, stream, &root, &errs))
{
cout << errs << endl;
return Completable::error(make_exception_ptr(runtime_error(errs)));
return Completable::error(runtime_error(errs));
}
return Completable::complete();
})
Expand Down
9 changes: 9 additions & 0 deletions include/recpp/rx/Completable.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ namespace recpp::rx
*/
static Completable error(const std::exception_ptr &error);

/**
* @brief Construct a new {@link Completable} instance that will emit the given error when subscribed to.
*
* @param error The error to emit.
* @return The new {@link Completable} instance.
*/
template <typename E>
static Completable error(E error);

/**
* @brief Construct a new {@link Completable} instance that will never emit a signal when subscribed to.
*
Expand Down
9 changes: 9 additions & 0 deletions include/recpp/rx/Maybe.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ namespace recpp::rx
*/
static Maybe<T> error(const std::exception_ptr &error);

/**
* @brief Construct a new {@link Maybe} instance that will emit the given error when subscribed to.
*
* @param error The error to emit.
* @return The new {@link Maybe} instance.
*/
template <typename E>
static Maybe<T> error(E error);

/**
* @brief Construct a new {@link Maybe} instance that will emit the given value when subscribed to.
*
Expand Down
9 changes: 9 additions & 0 deletions include/recpp/rx/Observable.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ namespace recpp::rx
*/
static Observable<T> error(const std::exception_ptr &error);

/**
* @brief Construct a new {@link Observable} instance that will emit the given error when subscribed to.
*
* @param error The error to emit.
* @return The new {@link Observable} instance.
*/
template <typename E>
static Observable<T> error(E error);

/**
* @brief Construct a new {@link Observable} instance that will emit the given value when subscribed to.
*
Expand Down
9 changes: 9 additions & 0 deletions include/recpp/rx/Single.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ namespace recpp::rx
*/
static Single<T> error(const std::exception_ptr &error);

/**
* @brief Construct a new {@link Single} instance that will emit the given error when subscribed to.
*
* @param error The error to emit.
* @return The new {@link Single} instance.
*/
template <typename E>
static Single<T> error(E error);

/**
* @brief Construct a new {@link Single} instance that will emit the given value when subscribed to.
*
Expand Down
8 changes: 8 additions & 0 deletions include/recpp/rx/inl/Completable.inl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
#include <recpp/rx/Observable.h>
#include <recpp/rx/Single.h>

#include <exception>

template <typename E>
recpp::rx::Completable recpp::rx::Completable::error(E error)
{
return Completable::error(std::make_exception_ptr(error));
}

template <typename T>
recpp::rx::Maybe<T> recpp::rx::Completable::andThen(const recpp::rx::Maybe<T> &maybe)
{
Expand Down
9 changes: 9 additions & 0 deletions include/recpp/rx/inl/Maybe.inl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <recpp/subscribers/DefaultSubscriber.h>
#include <recpp/subscribers/MaybeSubscriber.h>

#include <exception>

template <typename T>
recpp::rx::Maybe<T> recpp::rx::Maybe<T>::create(const std::function<void(recpp::subscribers::MaybeSubscriber<T> &)> &method)
{
Expand All @@ -43,6 +45,13 @@ recpp::rx::Maybe<T> recpp::rx::Maybe<T>::error(const std::exception_ptr &error)
return Maybe<T>(std::make_shared<recpp::publishers::ErrorPublisher<T>>(error));
}

template <typename T>
template <typename E>
recpp::rx::Maybe<T> recpp::rx::Maybe<T>::error(E error)
{
return Maybe<T>::error(std::make_exception_ptr(error));
}

template <typename T>
recpp::rx::Maybe<T> recpp::rx::Maybe<T>::just(const T &value)
{
Expand Down
9 changes: 9 additions & 0 deletions include/recpp/rx/inl/Observable.inl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include <recpp/subscribers/DefaultSubscriber.h>
#include <recpp/subscribers/ObservableSubscriber.h>

#include <exception>

template <typename T>
recpp::rx::Observable<T> recpp::rx::Observable<T>::create(const std::function<void(recpp::subscribers::ObservableSubscriber<T> &)> &method)
{
Expand All @@ -58,6 +60,13 @@ recpp::rx::Observable<T> recpp::rx::Observable<T>::error(const std::exception_pt
return Observable<T>(std::make_shared<recpp::publishers::ErrorPublisher<T>>(error));
}

template <typename T>
template <typename E>
recpp::rx::Observable<T> recpp::rx::Observable<T>::error(E error)
{
return Observable<T>::error(std::make_exception_ptr(error));
}

template <typename T>
recpp::rx::Observable<T> recpp::rx::Observable<T>::just(const T &value)
{
Expand Down
9 changes: 9 additions & 0 deletions include/recpp/rx/inl/Single.inl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <recpp/subscribers/DefaultSubscriber.h>
#include <recpp/subscribers/SingleSubscriber.h>

#include <exception>

template <typename T>
recpp::rx::Single<T> recpp::rx::Single<T>::create(const std::function<void(recpp::subscribers::SingleSubscriber<T> &)> &method)
{
Expand All @@ -37,6 +39,13 @@ recpp::rx::Single<T> recpp::rx::Single<T>::error(const std::exception_ptr &error
return Single<T>(std::make_shared<recpp::publishers::ErrorPublisher<T>>(error));
}

template <typename T>
template <typename E>
recpp::rx::Single<T> recpp::rx::Single<T>::error(E error)
{
return Single<T>::error(std::make_exception_ptr(error));
}

template <typename T>
recpp::rx::Single<T> recpp::rx::Single<T>::just(const T &value)
{
Expand Down
10 changes: 10 additions & 0 deletions include/recpp/subscribers/CompletableSubscriber.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ namespace recpp::subscribers
*/
void onError(const std::exception_ptr &error);

/**
* @brief Emits the given error to the {@link rscpp::Subscriber} if it has not already been emitted.
*
* @param error The error to emit.
*/
template <typename E>
void onError(E error);

/**
* @brief Emits a completion signal to the {@link rscpp::Subscriber} if it has not already been emitted.
*/
Expand All @@ -38,3 +46,5 @@ namespace recpp::subscribers
bool m_ended = false;
};
} // namespace recpp::subscribers

#include <recpp/subscribers/inl/CompletableSubscriber.inl>
8 changes: 8 additions & 0 deletions include/recpp/subscribers/MaybeSubscriber.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ namespace recpp::subscribers
*/
void onError(const std::exception_ptr &error);

/**
* @brief Emits the given error to the {@link rscpp::Subscriber} if it has not already been emitted.
*
* @param error The error to emit.
*/
template <typename E>
void onError(E error);

/**
* @brief Emits a completion signal to the {@link rscpp::Subscriber} if it has not already been emitted.
*/
Expand Down
8 changes: 8 additions & 0 deletions include/recpp/subscribers/ObservableSubscriber.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ namespace recpp::subscribers
*/
void onError(const std::exception_ptr &error);

/**
* @brief Emits the given error to the {@link rscpp::Subscriber} if it has not already been emitted.
*
* @param error The error to emit.
*/
template <typename E>
void onError(E error);

/**
* @brief Emits a completion signal to the {@link rscpp::Subscriber} if it has not already been emitted.
*/
Expand Down
8 changes: 8 additions & 0 deletions include/recpp/subscribers/SingleSubscriber.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ namespace recpp::subscribers
*/
void onError(const std::exception_ptr &error);

/**
* @brief Emits the given error to the {@link rscpp::Subscriber} if it has not already been emitted.
*
* @param error The error to emit.
*/
template <typename E>
void onError(E error);

private:
rscpp::Subscriber<T> m_subscriber;
bool m_ended = false;
Expand Down
9 changes: 9 additions & 0 deletions include/recpp/subscribers/inl/CompletableSubscriber.inl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include <exception>

template <typename E>
void recpp::subscribers::CompletableSubscriber::onError(E error)
{
onError(std::make_exception_ptr(error));
}
9 changes: 9 additions & 0 deletions include/recpp/subscribers/inl/MaybeSubscriber.inl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <exception>

template <typename T>
recpp::subscribers::MaybeSubscriber<T>::MaybeSubscriber(const rscpp::Subscriber<T> &subscriber)
: m_subscriber(subscriber)
Expand Down Expand Up @@ -27,6 +29,13 @@ void recpp::subscribers::MaybeSubscriber<T>::onError(const std::exception_ptr &e
}
}

template <typename T>
template <typename E>
void recpp::subscribers::MaybeSubscriber<T>::onError(E error)
{
onError(std::make_exception_ptr(error));
}

template <typename T>
void recpp::subscribers::MaybeSubscriber<T>::onComplete()
{
Expand Down
9 changes: 9 additions & 0 deletions include/recpp/subscribers/inl/ObservableSubscriber.inl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <exception>

template <typename T>
recpp::subscribers::ObservableSubscriber<T>::ObservableSubscriber(const rscpp::Subscriber<T> &subscriber)
: m_subscriber(subscriber)
Expand All @@ -23,6 +25,13 @@ void recpp::subscribers::ObservableSubscriber<T>::onError(const std::exception_p
}
}

template <typename T>
template <typename E>
void recpp::subscribers::ObservableSubscriber<T>::onError(E error)
{
onError(std::make_exception_ptr(error));
}

template <typename T>
void recpp::subscribers::ObservableSubscriber<T>::onComplete()
{
Expand Down
9 changes: 9 additions & 0 deletions include/recpp/subscribers/inl/SingleSubscriber.inl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <exception>

template <typename T>
recpp::subscribers::SingleSubscriber<T>::SingleSubscriber(const rscpp::Subscriber<T> &subscriber)
: m_subscriber(subscriber)
Expand All @@ -26,3 +28,10 @@ void recpp::subscribers::SingleSubscriber<T>::onError(const std::exception_ptr &
m_subscriber.onError(error);
}
}

template <typename T>
template <typename E>
void recpp::subscribers::SingleSubscriber<T>::onError(E error)
{
onError(std::make_exception_ptr(error));
}
2 changes: 1 addition & 1 deletion rscpp
Loading