Github user phrocker commented on a diff in the pull request:
https://github.com/apache/nifi-minifi-cpp/pull/71#discussion_r108924995
--- Diff: libminifi/include/utils/ThreadPool.h ---
@@ -0,0 +1,287 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 LIBMINIFI_INCLUDE_THREAD_POOL_H
+#define LIBMINIFI_INCLUDE_THREAD_POOL_H
+
+#include <iostream>
+#include <atomic>
+#include <mutex>
+#include <vector>
+#include <queue>
+#include <future>
+#include <thread>
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+
+/**
+ * Worker task
+ * purpose: Provides a wrapper for the functor
+ * and returns a future based on the template argument.
+ */
+template< typename T>
+class Worker{
+public:
+ explicit Worker(std::function<T()> &task) : task(task)
+ {
+ promise = std::make_shared<std::promise<T>>();
+ }
+
+ /**
+ * Move constructor for worker tasks
+ */
+ Worker(Worker &&other) : task (std::move(other.task)),
+ promise(other.promise)
+ {
+ }
+
+
+ /**
+ * Runs the task and takes the output from the funtor
+ * setting the result into the promise
+ */
+ void run()
+ {
+ T result = task();
+ promise->set_value(result);
+ }
+
+ Worker<T>(const Worker<T>&) = delete;
+ Worker<T>& operator = (const Worker<T>&) = delete;
+
+ Worker<T>& operator = (Worker<T>&&) ;
+
+ std::shared_ptr<std::promise<T>> getPromise();
+
+private:
+ std::function<T()> task;
+ std::shared_ptr<std::promise<T>> promise;
+};
+
+template< typename T>
--- End diff --
comment to remind people that && will take ownership of Worker
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---