diff --git a/src/entt/process/process.hpp b/src/entt/process/process.hpp index 76a5d0a05..e694edc49 100644 --- a/src/entt/process/process.hpp +++ b/src/entt/process/process.hpp @@ -187,8 +187,7 @@ public: * @return The newly assigned child process. */ std::shared_ptr then(std::shared_ptr child) { - next = std::move(child); - return this->shared_from_this(); + return (next = std::move(child)); } /** diff --git a/src/entt/process/scheduler.hpp b/src/entt/process/scheduler.hpp index cdad98f4b..c7d1222c9 100644 --- a/src/entt/process/scheduler.hpp +++ b/src/entt/process/scheduler.hpp @@ -146,12 +146,11 @@ public: * @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. + * @return The newly assigned child process. */ template - basic_scheduler &attach(std::shared_ptr proc) { - handlers.first().emplace_back(std::move(proc)); - return *this; + std::shared_ptr attach(std::shared_ptr proc) { + return handlers.first().emplace_back(std::move(proc)); } /** diff --git a/test/entt/process/process.cpp b/test/entt/process/process.cpp index 962ce7422..afbfbcd07 100644 --- a/test/entt/process/process.cpp +++ b/test/entt/process/process.cpp @@ -190,7 +190,7 @@ TEST(Process, ThenPeek) { ASSERT_FALSE(process->peek()); - process->then(std::make_shared>()->then(std::make_shared>())); + process->then(std::make_shared>())->then(std::make_shared>()); ASSERT_TRUE(process->peek()); ASSERT_TRUE(process->peek()->peek()); diff --git a/test/entt/process/scheduler.cpp b/test/entt/process/scheduler.cpp index cf5fee144..27e4e1016 100644 --- a/test/entt/process/scheduler.cpp +++ b/test/entt/process/scheduler.cpp @@ -108,13 +108,20 @@ TEST(Scheduler, Then) { entt::scheduler scheduler{}; std::pair counter{}; - scheduler - // failing process with successor - .attach(std::make_shared()->then(std::make_shared()->then(std::make_shared()->then(std::make_shared())))) - // failing process without successor - .attach(std::make_shared()->then(std::make_shared()->then(std::make_shared()))) - // non-failing process - .attach(std::make_shared()->then(std::make_shared())); + // failing process with successor + scheduler.attach(std::make_shared()) + ->then(std::make_shared()) + ->then(std::make_shared()) + ->then(std::make_shared()); + + // failing process without successor + scheduler.attach(std::make_shared()) + ->then(std::make_shared()) + ->then(std::make_shared()); + + // non-failing process + scheduler.attach(std::make_shared()) + ->then(std::make_shared()); while(!scheduler.empty()) { scheduler.update(0, &counter); @@ -142,7 +149,9 @@ TEST(Scheduler, Functor) { proc.fail(); }; - scheduler.attach(entt::process_from(std::move(attach))->then(entt::process_from(std::move(then))->then(entt::process_from([](entt::process &, std::uint32_t, void *) { FAIL(); })))); + scheduler.attach(entt::process_from(std::move(attach))) + ->then(entt::process_from(std::move(then))) + ->then(entt::process_from([](entt::process &, std::uint32_t, void *) { FAIL(); })); while(!scheduler.empty()) { scheduler.update(0); @@ -158,7 +167,7 @@ TEST(Scheduler, SpawningProcess) { std::pair counter{}; scheduler.attach(entt::process_from([&scheduler](entt::process &proc, std::uint32_t, void *) { - scheduler.attach(std::make_shared()->then(std::make_shared())); + scheduler.attach(std::make_shared())->then(std::make_shared()); proc.succeed(); }));