File indexing completed on 2024-04-28 16:53:07

0001 /*
0002  *   SPDX-FileCopyrightText: 2017 Ivan Čukić <ivan.cukic(at)kde.org>
0003  *
0004  *   SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005  */
0006 
0007 #ifndef ASYNQT_BASE_LISTEN_H
0008 #define ASYNQT_BASE_LISTEN_H
0009 
0010 #include <QFuture>
0011 #include <QFutureWatcher>
0012 
0013 #include "../private/operations/listen_p.h"
0014 
0015 namespace AsynQt
0016 {
0017 /**
0018  *
0019  */
0020 template<typename _Result, typename _Function>
0021 QFuture<_Result> onFinished(const QFuture<_Result> &future, _Function &&function)
0022 {
0023     return detail::onFinished_impl(future, std::forward<_Function>(function));
0024 }
0025 
0026 /**
0027  *
0028  */
0029 template<typename _Result, typename _Function>
0030 QFuture<_Result> onSuccess(const QFuture<_Result> &future, _Function &&function)
0031 {
0032     return onFinished(future, detail::PassResult<_Function>(function));
0033 }
0034 
0035 /**
0036  *
0037  */
0038 template<typename _Result, typename _Function>
0039 QFuture<_Result> onError(const QFuture<_Result> &future, _Function &&function)
0040 {
0041     return onFinished(future, detail::PassError<_Function>(function));
0042 }
0043 
0044 namespace operators
0045 {
0046 template<typename _Function>
0047 inline detail::operators::OnFinishedModifier<_Function> onFinished(_Function &&function)
0048 {
0049     return detail::operators::OnFinishedModifier<_Function>(std::forward<_Function>(function));
0050 }
0051 
0052 template<typename _Function>
0053 inline detail::operators::OnFinishedModifier<detail::PassResult<_Function>> onSuccess(_Function &&function)
0054 {
0055     return detail::operators::OnFinishedModifier<detail::PassResult<_Function>>(detail::PassResult<_Function>(function));
0056 }
0057 
0058 template<typename _Function>
0059 inline detail::operators::OnFinishedModifier<detail::PassError<_Function>> onError(_Function &&function)
0060 {
0061     return detail::operators::OnFinishedModifier<detail::PassError<_Function>>(detail::PassError<_Function>(function));
0062 }
0063 
0064 } // namespace operators
0065 
0066 } // namespace AsynQt
0067 
0068 #endif // include guard