Dobby 3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
Loading...
Searching...
No Matches
DobbyAsync.h
1/*
2* If not stated otherwise in this file or this component's LICENSE file the
3* following copyright and licenses apply:
4*
5* Copyright 2017 Sky UK
6*
7* Licensed under the Apache License, Version 2.0 (the "License");
8* you may not use this file except in compliance with the License.
9* You may obtain a copy of the License at
10*
11* http://www.apache.org/licenses/LICENSE-2.0
12*
13* Unless required by applicable law or agreed to in writing, software
14* distributed under the License is distributed on an "AS IS" BASIS,
15* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16* See the License for the specific language governing permissions and
17* limitations under the License.
18*/
19/*
20 * File: DobbyAsync.h
21 *
22 */
23#ifndef DOBBYASYNC_H
24#define DOBBYASYNC_H
25
26
27#include <string>
28#include <memory>
29#include <functional>
30
31
34
35
36std::shared_ptr<DobbyAsyncResult> DobbyAsyncImpl(const std::string &name,
37 const std::function<bool()>& func);
38std::shared_ptr<DobbyAsyncResult> DobbyDeferredImpl(const std::function<bool()>& func);
39
40
41
42// -----------------------------------------------------------------------------
55{
56private:
57 friend std::shared_ptr<DobbyAsyncResult> DobbyAsyncImpl(const std::string &name,
58 const std::function<bool()>& func);
59 friend std::shared_ptr<DobbyAsyncResult> DobbyDeferredImpl(const std::function<bool()>& func);
61
62public:
64
65public:
66 bool getResult();
67
68private:
69 IDobbyAsyncResultPrivate* const mPrivate;
70};
71
72
73
74
75// -----------------------------------------------------------------------------
87template< class Function >
88static inline std::shared_ptr<DobbyAsyncResult> DobbyAsync(const std::string &name,
89 Function func)
90{
91 return DobbyAsyncImpl(name, func);
92}
93
94template< class Function, class... Args >
95static inline std::shared_ptr<DobbyAsyncResult> DobbyAsync(const std::string &name,
96 Function&& f, Args&&... args)
97{
98 return DobbyAsyncImpl(name, std::bind(std::forward<Function>(f),
99 std::forward<Args>(args)...));
100}
101
102
103// -----------------------------------------------------------------------------
114template< class Function >
115static inline std::shared_ptr<DobbyAsyncResult> DobbyDeferred(Function func)
116{
117 return DobbyDeferredImpl(func);
118}
119
120template< class Function, class... Args >
121static inline std::shared_ptr<DobbyAsyncResult> DobbyDeferred(Function&& f, Args&&... args)
122{
123 return DobbyDeferredImpl(std::bind(std::forward<Function>(f),
124 std::forward<Args>(args)...));
125}
126
127
128#endif // !defined(DOBBYASYNC_H)
Result object for async and deferred results.
Definition DobbyAsync.h:55
Definition DobbyAsync.cpp:35