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