
#ifndef PLS_INVOKE_PARALLEL_IMPL_H
#define PLS_INVOKE_PARALLEL_IMPL_H

#include "pls/internal/scheduling/task.h"
#include "pls/internal/scheduling/lambda_task.h"
#include "pls/internal/scheduling/scheduler.h"

namespace pls {
namespace algorithm {

template<typename Function1, typename Function2>
void invoke_parallel(const Function1 &function1, const Function2 &function2) {
  using namespace ::pls::internal::scheduling;

  auto sub_task_2 = lambda_task_by_reference<Function2>(function2);

  scheduler::spawn_child(sub_task_2);
  function1(); // Execute first function 'inline' without spawning a sub_task object
  scheduler::wait_for_all();
}

template<typename Function1, typename Function2, typename Function3>
void invoke_parallel(const Function1 &function1, const Function2 &function2, const Function3 &function3) {
  using namespace ::pls::internal::scheduling;

  auto sub_task_2 = lambda_task_by_reference<Function2>(function2);
  auto sub_task_3 = lambda_task_by_reference<Function3>(function3);

  scheduler::spawn_child(sub_task_2);
  scheduler::spawn_child(sub_task_3);
  function1(); // Execute first function 'inline' without spawning a sub_task object
  scheduler::wait_for_all();
}

}
}

#endif //PLS_INVOKE_PARALLEL_IMPL_H
