c-resources/CPlusPlus20ForProgrammers-m.../examples/libraries/concurrencpp/source/results/promises.cpp

22 lines
867 B
C++
Raw Permalink Normal View History

2024-04-09 06:45:18 +00:00
#include "concurrencpp/results/promises.h"
#include "concurrencpp/coroutines/coroutine.h"
using concurrencpp::details::coroutine_per_thread_data;
thread_local coroutine_per_thread_data coroutine_per_thread_data::s_tl_per_thread_data;
void concurrencpp::details::initial_accumulating_awaiter::await_suspend(coroutine_handle<void> handle) noexcept {
m_await_context.set_coro_handle(handle);
auto& per_thread_data = coroutine_per_thread_data::s_tl_per_thread_data;
auto accumulator = std::exchange(per_thread_data.accumulator, nullptr);
assert(accumulator != nullptr);
assert(accumulator->capacity() > accumulator->size()); // so it's always noexcept
accumulator->emplace_back(await_via_functor {&m_await_context});
}
void concurrencpp::details::initial_accumulating_awaiter::await_resume() {
m_await_context.throw_if_interrupted();
}