Quellcode durchsuchen

兼容一些老项目

tags/v2.9.7
tearshark vor 4 Jahren
Ursprung
Commit
e0a5737240
2 geänderte Dateien mit 14 neuen und 7 gelöschten Zeilen
  1. 6
    3
      librf/src/sleep.h
  2. 8
    4
      librf/src/when_v2.h

+ 6
- 3
librf/src/sleep.h Datei anzeigen

template<class _Rep, class _Period> template<class _Rep, class _Period>
inline future_t<> sleep_for(std::chrono::duration<_Rep, _Period> dt_) inline future_t<> sleep_for(std::chrono::duration<_Rep, _Period> dt_)
{ {
co_await sleep_for_(std::chrono::duration_cast<std::chrono::system_clock::duration>(dt_), *current_scheduler());
scheduler_t* sch = current_scheduler();
co_await sleep_for_(std::chrono::duration_cast<std::chrono::system_clock::duration>(dt_), *sch);
} }
template<class _Clock, class _Duration> template<class _Clock, class _Duration>
inline future_t<> sleep_until(std::chrono::time_point<_Clock, _Duration> tp_) inline future_t<> sleep_until(std::chrono::time_point<_Clock, _Duration> tp_)
{ {
co_await sleep_until_(std::chrono::time_point_cast<std::chrono::system_clock::duration>(tp_), *current_scheduler());
scheduler_t* sch = current_scheduler();
co_await sleep_until_(std::chrono::time_point_cast<std::chrono::system_clock::duration>(tp_), *sch);
} }
template <class Rep, class Period> template <class Rep, class Period>
inline future_t<> operator co_await(std::chrono::duration<Rep, Period> dt_) inline future_t<> operator co_await(std::chrono::duration<Rep, Period> dt_)
{ {
co_await sleep_for(dt_, *current_scheduler());
scheduler_t* sch = current_scheduler();
co_await sleep_for(dt_, *sch);
} }
} }

+ 8
- 4
librf/src/when_v2.h Datei anzeigen

auto when_all(_Awaitable&&... awaitor) auto when_all(_Awaitable&&... awaitor)
-> future_t<std::tuple<detail::awaitor_result_t<_Awaitable>...>> -> future_t<std::tuple<detail::awaitor_result_t<_Awaitable>...>>
{ {
co_return co_await when_all(*current_scheduler(), std::forward<_Awaitable>(awaitor)...);
scheduler_t* sch = current_scheduler();
co_return co_await when_all(*sch, std::forward<_Awaitable>(awaitor)...);
} }


template<_WhenIterT _Iter template<_WhenIterT _Iter
auto when_all(_Iter begin, _Iter end) auto when_all(_Iter begin, _Iter end)
-> future_t<std::vector<detail::awaitor_result_t<decltype(*begin)>>> -> future_t<std::vector<detail::awaitor_result_t<decltype(*begin)>>>
{ {
co_return co_await when_all(*current_scheduler(), begin, end);
scheduler_t* sch = current_scheduler();
co_return co_await when_all(*sch, begin, end);
} }


template<_ContainerT _Cont template<_ContainerT _Cont
auto when_any(_Awaitable&&... awaitor) auto when_any(_Awaitable&&... awaitor)
-> future_t<when_any_pair> -> future_t<when_any_pair>
{ {
co_return co_await when_any(*current_scheduler(), std::forward<_Awaitable>(awaitor)...);
scheduler_t* sch = current_scheduler();
co_return co_await when_any(*sch, std::forward<_Awaitable>(awaitor)...);
} }


template<_WhenIterT _Iter template<_WhenIterT _Iter
auto when_any(_Iter begin, _Iter end) auto when_any(_Iter begin, _Iter end)
-> future_t<when_any_pair> -> future_t<when_any_pair>
{ {
co_return co_await when_any(*current_scheduler(), begin, end);
scheduler_t* sch = current_scheduler();
co_return co_await when_any(*sch, begin, end);
} }


template<_ContainerT _Cont template<_ContainerT _Cont

Laden…
Abbrechen
Speichern