feat support any safety task
This commit is contained in:
parent
015bb678cd
commit
61ee4ebeef
@ -8,6 +8,7 @@
|
|||||||
#define SLED_TASK_QUEUE_PENDING_TASK_SAFETY_FLAG_H
|
#define SLED_TASK_QUEUE_PENDING_TASK_SAFETY_FLAG_H
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include "sled/meta/type_traits.h"
|
||||||
#include "sled/ref_counted_base.h"
|
#include "sled/ref_counted_base.h"
|
||||||
#include "sled/scoped_refptr.h"
|
#include "sled/scoped_refptr.h"
|
||||||
#include "sled/synchronization/sequence_checker.h"
|
#include "sled/synchronization/sequence_checker.h"
|
||||||
@ -53,11 +54,30 @@ private:
|
|||||||
scoped_refptr<PendingTaskSafetyFlag> flag_;
|
scoped_refptr<PendingTaskSafetyFlag> flag_;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline std::function<void()>
|
// inline std::function<void()>
|
||||||
SafeTask(scoped_refptr<PendingTaskSafetyFlag> flag, std::function<void()> task)
|
// SafeTask(scoped_refptr<PendingTaskSafetyFlag> flag, std::function<void()> task)
|
||||||
|
// {
|
||||||
|
// return [flag, task]() mutable {
|
||||||
|
// if (flag->alive()) { std::move(task)(); }
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
|
||||||
|
template<typename F, typename... Args, typename = EnableIfT<!std::is_void<InvokeResultT<F, Args...>>::value>>
|
||||||
|
std::function<InvokeResultT<F, Args...>(Args &&...)>
|
||||||
|
SafeTask(scoped_refptr<PendingTaskSafetyFlag> flag, F &&f)
|
||||||
{
|
{
|
||||||
return [flag, task]() mutable {
|
return [flag, f](Args &&...args) mutable -> InvokeResultT<F, Args...> {
|
||||||
if (flag->alive()) { std::move(task)(); }
|
if (flag->alive()) { return f(std::forward<Args>(args)...); }
|
||||||
|
return {};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename F, typename... Args, typename = EnableIfT<std::is_void<InvokeResultT<F, Args...>>::value>>
|
||||||
|
std::function<void(Args &&...)>
|
||||||
|
SafeTask(scoped_refptr<PendingTaskSafetyFlag> flag, F &&f)
|
||||||
|
{
|
||||||
|
return [flag, f](Args &&...args) mutable -> void {
|
||||||
|
if (flag->alive()) { f(std::forward<Args>(args)...); }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user