AWS SDK for C++

AWS SDK for C++ Version 1.11.826

Loading...
Searching...
No Matches
AWSAsyncOperationTemplate.h
1
6#pragma once
7
8#include <aws/core/Core_EXPORTS.h>
9#include <aws/core/utils/memory/AWSMemory.h>
10#include <aws/core/utils/memory/stl/AWSAllocator.h>
11#include <aws/core/utils/threading/Executor.h>
12#include <functional>
13#include <future>
14
15namespace Aws
16{
17namespace Client
18{
22 template<typename ClientT,
23 typename RequestT,
24 typename HandlerT,
25 typename HandlerContextT,
26 typename OperationFuncT,
27 typename ExecutorT>
28 inline void AWS_CORE_LOCAL MakeAsyncOperation(OperationFuncT&& operationFunc,
29 const ClientT* clientThis,
30 const RequestT& request,
31 const HandlerT& handler,
32 const HandlerContextT& context,
33 ExecutorT* pExecutor)
34 {
35 std::function<void()> asyncTask =
36 [operationFunc, clientThis, request, handler, context]() // note capture by value
37 {
38 handler(clientThis,
39 request,
40 (clientThis->*operationFunc)(request),
41 context);
42 };
43
44 pExecutor->Submit(std::move(asyncTask));
45 }
46
53 template<typename ClientT,
54 typename RequestT,
55 typename HandlerT,
56 typename HandlerContextT,
57 typename OperationFuncT,
58 typename ExecutorT>
59 inline void AWS_CORE_LOCAL MakeAsyncStreamingOperation(OperationFuncT&& operationFunc,
60 const ClientT* clientThis,
61 RequestT& request, // note non-const ref
62 const HandlerT& handler,
63 const HandlerContextT& context,
64 ExecutorT* pExecutor)
65 {
66 std::function<void()> asyncTask =
67 [operationFunc, clientThis, &request, handler, context]() // note capture by ref
68 {
69 handler(clientThis,
70 request,
71 (clientThis->*operationFunc)(request),
72 context);
73 };
74
75 pExecutor->Submit(std::move(asyncTask));
76 }
77
81 template<typename ClientT,
82 typename HandlerT,
83 typename HandlerContextT,
84 typename OperationFuncT,
85 typename ExecutorT>
86 inline void AWS_CORE_LOCAL MakeAsyncOperation(OperationFuncT&& operationFunc,
87 const ClientT* clientThis,
88 const HandlerT& handler,
89 const HandlerContextT& context,
90 ExecutorT* pExecutor)
91 {
92 std::function<void()> asyncTask =
93 [operationFunc, clientThis, handler, context]()
94 {
95 handler(clientThis,
96 (clientThis->*operationFunc)(),
97 context);
98 };
99
100 pExecutor->Submit(std::move(asyncTask));
101 }
102
106 template<typename ClientT,
107 typename RequestT,
108 typename OperationFuncT,
109 typename ExecutorT>
110 inline auto AWS_CORE_LOCAL MakeCallableOperation(const char* ALLOCATION_TAG,
111 OperationFuncT&& operationFunc,
112 const ClientT* clientThis,
113 const RequestT& request,
114 ExecutorT* pExecutor) -> std::future<decltype((clientThis->*operationFunc)(request))>
115 {
116 using OperationOutcomeT = decltype((clientThis->*operationFunc)(request));
117
118 auto task = Aws::MakeShared< std::packaged_task< OperationOutcomeT() > >(
119 ALLOCATION_TAG,
120 [clientThis, operationFunc, request]() // note capture by value
121 {
122 auto futureOutcome = (clientThis->*operationFunc)(request);
123 return futureOutcome;
124 } );
125
126 std::function<void()> packagedFunction =
127 [task]() { (*task)(); };
128 pExecutor->Submit(std::move(packagedFunction));
129 return task->get_future();
130 }
131
138 template<typename ClientT,
139 typename RequestT,
140 typename OperationFuncT,
141 typename ExecutorT>
142 inline auto AWS_CORE_LOCAL MakeCallableStreamingOperation(const char* ALLOCATION_TAG,
143 OperationFuncT&& operationFunc,
144 const ClientT* clientThis,
145 RequestT& request, // note non-const ref
146 ExecutorT* pExecutor) -> std::future<decltype((clientThis->*operationFunc)(request))>
147 {
148 using OperationOutcomeT = decltype((clientThis->*operationFunc)(request));
149
150 auto task = Aws::MakeShared< std::packaged_task< OperationOutcomeT() > >(
151 ALLOCATION_TAG,
152 [clientThis, operationFunc, &request]() // note capture by ref
153 {
154 return (clientThis->*operationFunc)(request);
155 } );
156
157 std::function<void()> packagedFunction =
158 [task]() { (*task)(); };
159 pExecutor->Submit(std::move(packagedFunction));
160 return task->get_future();
161 }
162
166 template<typename ClientT,
167 typename OperationFuncT,
168 typename ExecutorT>
169 inline auto AWS_CORE_LOCAL MakeCallableOperation(const char* ALLOCATION_TAG,
170 OperationFuncT&& operationFunc,
171 const ClientT* clientThis,
172 ExecutorT* pExecutor) -> std::future<decltype((clientThis->*operationFunc)())>
173 {
174 using OperationOutcomeT = decltype((clientThis->*operationFunc)());
175
176 auto task = Aws::MakeShared< std::packaged_task< OperationOutcomeT() > >(
177 ALLOCATION_TAG,
178 [clientThis, operationFunc]()
179 {
180 return (clientThis->*operationFunc)();
181 } );
182
183 std::function<void()> packagedFunction =
184 [task]() { (*task)(); };
185 pExecutor->Submit(std::move(packagedFunction));
186 return task->get_future();
187 }
188} // namespace Client
189} // namespace Aws
190
191
auto AWS_CORE_LOCAL MakeCallableOperation(const char *ALLOCATION_TAG, OperationFuncT &&operationFunc, const ClientT *clientThis, const RequestT &request, ExecutorT *pExecutor) -> std::future< decltype((clientThis-> *operationFunc)(request))>
void AWS_CORE_LOCAL MakeAsyncOperation(OperationFuncT &&operationFunc, const ClientT *clientThis, const RequestT &request, const HandlerT &handler, const HandlerContextT &context, ExecutorT *pExecutor)
void AWS_CORE_LOCAL MakeAsyncStreamingOperation(OperationFuncT &&operationFunc, const ClientT *clientThis, RequestT &request, const HandlerT &handler, const HandlerContextT &context, ExecutorT *pExecutor)
auto AWS_CORE_LOCAL MakeCallableStreamingOperation(const char *ALLOCATION_TAG, OperationFuncT &&operationFunc, const ClientT *clientThis, RequestT &request, ExecutorT *pExecutor) -> std::future< decltype((clientThis-> *operationFunc)(request))>
std::shared_ptr< T > MakeShared(const char *allocationTag, ArgTypes &&... args)