/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef META_API_TASK_H
#define META_API_TASK_H
#include
#include
#include
#include
META_BEGIN_NAMESPACE()
/**
* @brief Implementation of waitable task for task queues (see ITaskQueue::AddWaitableTask)
*/
template
class QueueWaitableTask : public IntroduceInterfaces {
public:
QueueWaitableTask(Func func) : func_(BASE_NS::move(func)) {}
IAny::Ptr Invoke() override
{
using Result = BASE_NS::remove_reference_t;
if constexpr (!BASE_NS::is_same_v) {
return IAny::Ptr(new Any(func_()));
} else {
func_();
return nullptr;
}
}
private:
Func func_;
};
/**
* @brief Create waitable task from callable entity (e.g. lambda).
*/
template
ITaskQueueWaitableTask::Ptr CreateWaitableTask(Func func)
{
return ITaskQueueWaitableTask::Ptr(new QueueWaitableTask(BASE_NS::move(func)));
}
META_END_NAMESPACE()
#endif