Commit 2c176465 authored by tqcq's avatar tqcq
Browse files

feat support Async Future scheduler

parent 28009f18
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -361,10 +361,11 @@ public:
    }

    template<typename Func, typename = EnableIfT<IsInvocable<Func>::value>>
    static Future<T, FailureT> Async(Func &&f) noexcept
    static Future<T, FailureT> Async(Func &&f, TaskQueueBase *scheduler = sled::GetDefaultScheduler()) noexcept
    {
        SLED_ASSERT(scheduler != nullptr, "TaskQueue is not valid");
        Future<T, FailureT> result = Future<T, FailureT>::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<T, FailureT> AsyncValue(const T &value) noexcept
    static Future<T, FailureT> AsyncValue(const T &value,
                                          TaskQueueBase *scheduler = sled::GetDefaultScheduler()) noexcept
    {
        return Async([value]() { return value; });
        return Async([value]() { return value; }, scheduler);
    }

    static Future<typename std::decay<T>::type, FailureT> Successful(T &&value) noexcept