userver: userver/engine/impl/context_accessor.hpp Source File
Loading...
Searching...
No Matches
context_accessor.hpp
1#pragma once
2
3USERVER_NAMESPACE_BEGIN
4
5namespace engine::impl {
6
7class TaskContext;
8
9template <typename T>
10class FutureWaitStrategy;
11
12enum class [[nodiscard]] EarlyWakeup : bool {};
13
14class ContextAccessor {
15 public:
16 virtual bool IsReady() const noexcept = 0;
17
18 // Atomically:
19 // 1. if not `IsReady`, then store `waiter` somewhere to notify when
20 // `IsReady() == true` is reached, and return `EarlyWakeup{false}`;
21 // 2. if `IsReady`, then notify `waiter` immediately via `Wakeup*`,
22 // and return `EarlyWakeup{true}`.
23 virtual EarlyWakeup TryAppendWaiter(TaskContext& waiter) = 0;
24
25 // Remove `waiter` from the internal wait list if it's still there.
26 // You may not sleep in `RemoveWaiter`, unlike in `AfterWait`.
27 virtual void RemoveWaiter(TaskContext& waiter) noexcept = 0;
28
29 // Wait for some cleanup (e.g. wait for `waiter` to actually remove itself).
30 // You may sleep in `AfterWait`.
31 virtual void AfterWait() noexcept = 0;
32
33 // Precondition: IsReady
34 // This method is required for WaitAllChecked to properly function.
35 virtual void RethrowErrorResult() const = 0;
36
37 protected:
38 ContextAccessor();
39
40 ~ContextAccessor() = default;
41};
42
43} // namespace engine::impl
44
45USERVER_NAMESPACE_END