KDDockWidgets API Documentation 2.0
Loading...
Searching...
No Matches
CoRoutines.cpp
Go to the documentation of this file.
1/*
2 This file is part of KDDockWidgets.
3
4 SPDX-FileCopyrightText: 2019 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
5 Author: SĂ©rgio Martins <sergio.martins@kdab.com>
6
7 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
8
9 Contact KDAB at <info@kdab.com> for commercial licensing options.
10*/
11
12#include "CoRoutines.h"
13
14#include <iostream>
15#include <queue>
16
17using namespace KDDockWidgets::flutter;
18
19class SuspendTask
20{
21public:
22 SuspendTask()
23 {
24 }
25
26 constexpr bool await_ready() const noexcept
27 {
28 return false;
29 }
30
31 void await_suspend(std::coroutine_handle<> h) const noexcept
32 {
33 // assert(!s_task);
34 // assert(!m_handle);
35 m_handle = h.address();
36 s_task = const_cast<SuspendTask *>(this);
37 }
38
39 void await_resume() const noexcept
40 {
41 }
42
43 void resume()
44 {
45 auto h = std::coroutine_handle<>::from_address(m_handle);
46 s_task = nullptr;
47 m_handle = nullptr;
48
49 h.resume();
50 }
51
52public:
53 static SuspendTask *s_task;
54
55private:
56 mutable void *m_handle = nullptr;
57};
58
59SuspendTask *SuspendTask::s_task = nullptr;
60
62{
63 co_await SuspendTask();
64}
65
67{
68 if (SuspendTask::s_task)
69 SuspendTask::s_task->resume();
70}
void resume()
Resumes the co-routine.
An asynchronously executed task.
Definition qcorotask.h:458

© Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
KDDockWidgets
Advanced Dock Widget Framework for Qt
https://www.kdab.com/development-resources/qt-tools/kddockwidgets/
Generated by doxygen 1.9.8