1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef META_INTERFACE_IPROMISE_H
16 #define META_INTERFACE_IPROMISE_H
17 
18 #include <meta/base/interface_macros.h>
19 #include <meta/base/time_span.h>
20 #include <meta/base/types.h>
21 #include <meta/interface/intf_any.h>
22 #include <meta/interface/intf_callable.h>
23 #include <meta/interface/intf_task_queue.h>
24 
META_BEGIN_NAMESPACE()25 META_BEGIN_NAMESPACE()
26 
27 /**
28  * @brief Promise to fulfill future
29  */
30 class IPromise : public CORE_NS::IInterface {
31     META_INTERFACE(CORE_NS::IInterface, IPromise);
32 
33 public:
34     /**
35      * @brief This will release waiting on associated future and sets the state to COMPLETED
36      */
37     virtual void Set(const IAny::Ptr&) = 0;
38     /**
39      * @brief This will release waiting on associated future and sets the state to ABANDONED
40      */
41     virtual void SetAbandoned() = 0;
42     /**
43      * @brief Get associated future
44      */
45     virtual IFuture::Ptr GetFuture() = 0;
46     /**
47      * @brief Set Executing task token and queue
48      */
49     virtual void SetQueueInfo(const ITaskQueue::Ptr& queue, ITaskQueue::Token token) = 0;
50 };
51 
52 /** Basic Promise implementations */
53 META_REGISTER_CLASS(Promise, "664797ae-14be-481a-a124-2da82593edcd", ObjectCategoryBits::NO_CATEGORY)
54 
55 META_END_NAMESPACE()
56 
57 META_INTERFACE_TYPE(META_NS::IPromise)
58 
59 #endif
60