Просмотр исходного кода

scheduler: add a plain attach for shared processes - see #1257

Michele Caini 8 месяцев назад
Родитель
Сommit
b5201a56df
2 измененных файлов с 13 добавлено и 4 удалено
  1. 12 0
      src/entt/process/scheduler.hpp
  2. 1 4
      test/entt/process/scheduler.cpp

+ 12 - 0
src/entt/process/scheduler.hpp

@@ -150,6 +150,18 @@ public:
         handlers.first().clear();
     }
 
+    /**
+     * @brief Schedules a process for the next tick.
+     * @tparam Proc Type of process to schedule.
+     * @param proc The actual process to schedule.
+     * @return This process scheduler.
+     */
+    template<typename Proc>
+    basic_scheduler &attach(std::shared_ptr<Proc> proc) {
+        handlers.first().emplace_back(std::move(proc));
+        return *this;
+    }
+
     /**
      * @brief Schedules a process for the next tick.
      *

+ 1 - 4
test/entt/process/scheduler.cpp

@@ -112,10 +112,7 @@ TEST(Scheduler, Then) {
 
     scheduler
         // failing process with successor
-        .attach<succeeded_process>()
-        .then<succeeded_process>()
-        .then<failed_process>()
-        .then<succeeded_process>()
+        .attach(std::make_shared<succeeded_process>()->then(std::make_shared<succeeded_process>()->then(std::make_shared<failed_process>()->then(std::make_shared<succeeded_process>()))))
         // failing process without successor
         .attach<succeeded_process>()
         .then<succeeded_process>()