MillicastSDK
2.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
promise.h
Go to the documentation of this file.
1
#pragma once
2
3
#ifdef __cplusplus
4
5
#include <functional>
6
7
#include "
error.h
"
8
#include "
exports.h
"
9
10
namespace
millicast {
11
12
namespace
detail {
13
template
<
typename
T>
14
struct
PromiseResultCbType {
15
using
Type = std::function<void(T&&)>;
16
};
17
18
template
<>
19
struct
PromiseResultCbType<void> {
20
using
Type = std::function<void()>;
21
};
22
23
template
<
typename
T>
24
class
PromiseImpl {
25
public
:
26
virtual
~PromiseImpl() =
default
;
27
virtual
void
on_result(
28
const
typename
detail::PromiseResultCbType<T>::Type& cb) = 0;
29
virtual
void
on_error(
const
std::function<
void
(
const
Error&)>& cb) = 0;
30
};
31
}
// namespace detail
32
46
template
<
typename
T>
47
class
MILLICAST_TEMPLATE_API
Promise {
48
public
:
49
Promise(std::unique_ptr<detail::PromiseImpl<T>> impl)
50
: _impl(std::move(impl)){};
51
Promise(
const
Promise&) =
delete
;
52
Promise(Promise&&) =
delete
;
53
Promise& operator=(
const
Promise&) =
delete
;
54
Promise& operator=(Promise&&) =
delete
;
55
63
Promise<T>& on_result(
64
const
typename
detail::PromiseResultCbType<T>::Type& cb) {
65
_impl->on_result(cb);
66
return
*
this
;
67
}
68
75
Promise<T>& on_error(
const
std::function<
void
(
const
Error&)>& cb) {
76
_impl->on_error(cb);
77
return
*
this
;
78
}
79
88
void
done() { _impl = {}; }
89
90
private
:
91
std::unique_ptr<detail::PromiseImpl<T>> _impl;
92
};
93
}
// namespace millicast
94
95
#endif
// __cplusplus
error.h
exports.h
MILLICAST_TEMPLATE_API
#define MILLICAST_TEMPLATE_API
Definition
exports.h:46
api
millicast-sdk
promise.h
Generated by
1.18.0