From 2c1764658e6ed4eb18c4c8251a972db702dc7eba Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Wed, 1 May 2024 06:48:38 +0000 Subject: [PATCH] feat support Async Future scheduler --- src/sled/futures/future.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/sled/futures/future.h b/src/sled/futures/future.h index 138a8a7..d806b44 100644 --- a/src/sled/futures/future.h +++ b/src/sled/futures/future.h @@ -361,10 +361,11 @@ public: } template::value>> - static Future Async(Func &&f) noexcept + static Future Async(Func &&f, TaskQueueBase *scheduler = sled::GetDefaultScheduler()) noexcept { + SLED_ASSERT(scheduler != nullptr, "TaskQueue is not valid"); Future result = Future::Create(); - sled::GetDefaultScheduler()->PostTask([result, f]() mutable noexcept { + scheduler->PostTask([result, f]() mutable noexcept { try { result.FillSuccess(f()); } catch (const std::exception &e) { @@ -376,9 +377,10 @@ public: return result; } - static Future AsyncValue(const T &value) noexcept + static Future AsyncValue(const T &value, + TaskQueueBase *scheduler = sled::GetDefaultScheduler()) noexcept { - return Async([value]() { return value; }); + return Async([value]() { return value; }, scheduler); } static Future::type, FailureT> Successful(T &&value) noexcept