userver: userver/storages/redis/impl/transaction_subrequest_data.hpp Source File
Loading...
Searching...
No Matches
transaction_subrequest_data.hpp
1#pragma once
2
3#include <stdexcept>
4#include <string>
5#include <string_view>
6
7#include <userver/engine/future.hpp>
8#include <userver/storages/redis/request_data_base.hpp>
9
10USERVER_NAMESPACE_BEGIN
11
12namespace storages::redis::impl {
13
14[[noreturn]] void ThrowTransactionNotStarted(std::string_view description);
15
16template <typename ReplyType>
17class TransactionSubrequestDataImpl final : public RequestDataBase<ReplyType> {
18 public:
19 TransactionSubrequestDataImpl(engine::Future<ReplyType> future)
20 : future_(std::move(future)) {}
21
22 void Wait() override { ThrowIfNotReady("Wait() for"); }
23
24 ReplyType Get(const std::string& /*request_description*/) override {
25 ThrowIfNotReady("Get()");
26 return future_.get();
27 }
28
29 ReplyPtr GetRaw() override {
30 throw std::logic_error("call TransactionSubrequestDataImpl::GetRaw()");
31 }
32
33 engine::impl::ContextAccessor* TryGetContextAccessor() noexcept override {
34 UASSERT_MSG(false, "Not implemented");
35 return nullptr;
36 }
37
38 private:
39 void ThrowIfNotReady(std::string_view description) {
40 if (future_.wait_until(engine::Deadline::Passed()) !=
41 engine::FutureStatus::kReady) {
42 ThrowTransactionNotStarted(description);
43 }
44 }
45
46 engine::Future<ReplyType> future_;
47};
48
49} // namespace storages::redis::impl
50
51USERVER_NAMESPACE_END