2 * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
28 Able to run a task in the thread pool. derive from the
29 task interface and implement run method.
31 To get the result call task->get() which will return immidiately if the
32 task is already finishd otherwise will wait till task completion.
38 virtual ~Task() = default;
39 void get() { if (_receiver.valid()) _receiver.get(); }
42 virtual void run() = 0;
51 _sender = std::promise<void>();
52 _receiver = _sender.get_future();
54 friend class Executor;
56 std::promise<void> _sender;
57 std::future<void> _receiver;
61 using shared_task = std::shared_ptr<Task>;
64 async() function takes a shared task and runs it in
65 a thread pool asyncronously. call get() on the shared_task
66 to get the ressult out of the shared_task.
68 void async(shared_task task);