LeechCraft 0.6.70-18808-g3467692359
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
finalsuspender.h
Go to the documentation of this file.
1/**********************************************************************
2 * LeechCraft - modular cross-platform feature rich internet client.
3 * Copyright (C) 2006-2014 Georg Rudoy
4 *
5 * Distributed under the Boost Software License, Version 1.0.
6 * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7 **********************************************************************/
8
9#pragma once
10
11#include <coroutine>
12#include <mutex>
13
14namespace LC::Util::detail
15{
16 template<typename Promise>
18 {
19 Promise& Promise_;
20
21 bool await_ready () const noexcept { return false; }
22
23 std::coroutine_handle<> await_suspend (std::coroutine_handle<>) noexcept
24 {
25 auto handles = [this]
26 {
27 std::lock_guard guard { Promise_ };
28 return Promise_.GetAwaiters ();
29 } ();
30 Promise_.DecRef ();
31
32 if constexpr (std::is_same_v<decltype (handles), std::coroutine_handle<>>)
33 return handles ? handles : std::noop_coroutine ();
34 else
35 {
36 if (handles.size () == 1)
37 return handles [0];
38
39 for (const auto& h : handles)
40 h.resume ();
41 return std::noop_coroutine ();
42 }
43 }
44
45 void await_resume () const noexcept {}
46 };
47}
void await_resume() const noexcept
std::coroutine_handle await_suspend(std::coroutine_handle<>) noexcept
bool await_ready() const noexcept