HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
awaitable_stop_token_impl.hpp
1// Copyright Take Vos 2023.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "awaitable_stop_token_intf.hpp"
8#include "loop_win32_intf.hpp"
9#include "../macros.hpp"
10#include <utility>
11#include <coroutine>
12#include <chrono>
13#include <stop_token>
14
15hi_export_module(hikogui.dispatch : awaitable_stop_token_impl);
16
17hi_export namespace hi::inline v1 {
18
19inline void awaitable_stop_token::callback_wrapper::operator()() noexcept
20{
21 // Stop tokens are specifically designed to be called from a different thread,
22 // so we will post the function to the same thread as the co_await.
23 await_loop->post_function([this]() {
24 if (handle and not handle.done()) {
25 handle.resume();
26 }
27 });
28}
29
30inline void awaitable_stop_token::await_suspend(std::coroutine_handle<> handle) noexcept
31{
32 _stop_callback_ptr = std::make_unique<std::stop_callback<callback_wrapper>>(_stop_token, callback_wrapper{&loop::local(), handle});
33}
34
35}
DOXYGEN BUG.
Definition algorithm_misc.hpp:20