MillicastSDK 2.0.0
Loading...
Searching...
No Matches
promise.h
Go to the documentation of this file.
1#pragma once
2
3#include <functional>
4
7
8namespace millicast {
9
10namespace detail {
11template <typename T>
13 using Type = std::function<void(T&&)>;
14};
15
16template <>
17struct PromiseResultCbType<void> {
18 using Type = std::function<void()>;
19};
20
21template <typename T>
23 public:
24 virtual ~PromiseImpl() = default;
25 virtual void on_result(
26 const typename detail::PromiseResultCbType<T>::Type& cb) = 0;
27 virtual void on_error(const std::function<void(const Error&)>& cb) = 0;
28};
29} // namespace detail
30
44template <typename T>
46 public:
47 Promise(std::unique_ptr<detail::PromiseImpl<T>> impl)
48 : _impl(std::move(impl)){};
49 Promise(const Promise&) = delete;
50 Promise(Promise&&) = delete;
51 Promise& operator=(const Promise&) = delete;
53
62 const typename detail::PromiseResultCbType<T>::Type& cb) {
63 _impl->on_result(cb);
64 return *this;
65 }
66
73 Promise<T>& on_error(const std::function<void(const Error&)>& cb) {
74 _impl->on_error(cb);
75 return *this;
76 }
77
86 void done() { _impl = {}; }
87
88 private:
89 std::unique_ptr<detail::PromiseImpl<T>> _impl;
90};
91} // namespace millicast
The errors reported by the Millicast SDK.
Definition error.h:16
Definition promise.h:45
Promise(std::unique_ptr< detail::PromiseImpl< T > > impl)
Definition promise.h:47
Promise(Promise &&)=delete
void done()
Definition promise.h:86
Promise & operator=(const Promise &)=delete
Promise(const Promise &)=delete
Promise & operator=(Promise &&)=delete
Promise< T > & on_result(const typename detail::PromiseResultCbType< T >::Type &cb)
Definition promise.h:61
Promise< T > & on_error(const std::function< void(const Error &)> &cb)
Definition promise.h:73
Definition promise.h:22
virtual void on_error(const std::function< void(const Error &)> &cb)=0
virtual ~PromiseImpl()=default
virtual void on_result(const typename detail::PromiseResultCbType< T >::Type &cb)=0
#define MILLICAST_TEMPLATE_API
Definition exports.h:46
Definition capabilities.h:15
Definition error.h:209
std::function< void()> Type
Definition promise.h:18
std::function< void(T &&)> Type
Definition promise.h:13