17#ifndef CYBER_TASK_TASK_H_
18#define CYBER_TASK_TASK_H_
30template <
typename F,
typename... Args>
31static auto Async(F&&
f, Args&&... args)
32 -> std::future<
typename std::result_of<F(Args...)>::type> {
33 return GlobalData::Instance()->IsRealityMode()
34 ? TaskManager::Instance()->Enqueue(std::forward<F>(
f),
35 std::forward<Args>(args)...)
38 std::bind(std::forward<F>(
f), std::forward<Args>(args)...));
41static inline void Yield() {
45 std::this_thread::yield();
49template <
typename Rep,
typename Period>
50static void SleepFor(
const std::chrono::duration<Rep, Period>& sleep_duration) {
52 if (routine ==
nullptr) {
53 std::this_thread::sleep_for(sleep_duration);
55 routine->Sleep(sleep_duration);
59static inline void USleep(useconds_t usec) {
61 if (routine ==
nullptr) {
62 std::this_thread::sleep_for(std::chrono::microseconds{usec});
static CRoutine * GetCurrentRoutine()
std::chrono::microseconds Duration